On Wednesday, 23 August 2017 at 14:37:19 UTC, Steven Schveighoffer wrote:
On 8/23/17 9:12 AM, Mike Parker wrote:
To coincide with the improvements to -betterC in the upcoming DMD 2.076, Walter has published a new article on the D blog about what it is and why to use it. A fun read. And I'm personally happy to see the love this feature is getting. I have a project I'd like to use it with if I can ever make the time for it!


The blog:

https://dlang.org/blog/2017/08/23/d-as-a-better-c/

Reddit:
https://www.reddit.com/r/programming/comments/6viswu/d_as_a_better_c/

How do dynamic closures work without the GC?

Nice article, BTW.

-Steve

They don't (right now, using dmd ~master), because they depend on druntime:

--- a.c ---
#include <stdio.h>
#include <stdint.h>

uint32_t foo();

int main(int argc, char** argv)
{
    uint32_t x = foo();
    printf("%d\n", x);
}
-----------

--- b.d ---
auto test()
{
    uint i = 42;
    return () {
        return i;
    };
}

oo()
{
    auto x = test();
    return x();
}
-----------

$ dmd -c -betterC b.d
$ gcc a.c b.d
Undefined symbols for architecture x86_64:
  "__d_allocmemory", referenced from:
      _D1b4testFNaNbNfZDFNaNbNiNfZk in b.o
ld: symbol(s) not found for architecture x86_64extern(C) uint foo()
{
    auto x = test();
    return x();
}
-----------

$ dmd -c -betterC b.d
$ gcc a.c b.d
Undefined symbols for architecture x86_64:
  "__d_allocmemory", referenced from:
      _D1b4testFNaNbNfZDFNaNbNiNfZk in b.o

Reply via email to