digitalmars.D.learn - Nested functions and their linkage type
- kdevel (24/24) Jan 23 2021 In § 19.18.7 [1] it is said that
- Mike Parker (5/12) Jan 23 2021 I assume because of mangling. The outer function is mangled into
- Mike Parker (3/11) Jan 23 2021 And also that nested functions needs to reference the stack of
In § 19.18.7 [1] it is said that Nested functions always have the D function linkage type. Why and for what application is that important? As this example ~~~znested.d void foo () { } unittest { void nested () { } import std.stdio; writeln (typeof (nested).stringof); writeln (typeof (&nested).stringof); writeln (typeof (foo).stringof); writeln (typeof (&foo).stringof); } ~~~ $ dmd -unittest -checkaction=context -main -run znested.d pure nothrow nogc safe void() void delegate() pure nothrow nogc safe void() void function() 1 unittests passed shows from the object with D function linkage type named "nested" a delegate is created as soon as its address is taken. (function pointers are only generated from static nested functions) [1] https://dlang.org/spec/function.html#nested
Jan 23 2021
On Saturday, 23 January 2021 at 20:37:49 UTC, kdevel wrote:In § 19.18.7 [1] it is said that Nested functions always have the D function linkage type. Why and for what application is that important?I assume because of mangling. The outer function is mangled into the nested function's name.shows from the object with D function linkage type named "nested" a delegate is created as soon as its address is taken. (function pointers are only generated from static nested functions)Yes. That's documented here: https://dlang.org/spec/function.html#closures
Jan 23 2021
On Sunday, 24 January 2021 at 02:30:37 UTC, Mike Parker wrote:On Saturday, 23 January 2021 at 20:37:49 UTC, kdevel wrote:And also that nested functions needs to reference the stack of the enclosing function.In § 19.18.7 [1] it is said that Nested functions always have the D function linkage type. Why and for what application is that important?I assume because of mangling. The outer function is mangled into the nested function's name.
Jan 23 2021