On 10/08/2018 9:57 PM, learnfirst1 wrote:

import core.stdc.stdio;

struct Test {
     string name ;
}

void T(alias pred, A...)(){
     __gshared t = Test(A) ;
      pred(t);
}

extern(C) void main(){
    T!(t => printf("test 1 name = %s\n".ptr, t.name.ptr), "test") ; // build OK
     T!(t => {
         printf("test 2 name = %s\n".ptr, t.name.ptr);
     }, "test") ; // build error
}

--------------

build this with betterC

Undefined symbols for architecture x86_64:
   "__d_allocmemory", referenced from:
      __D4test4mainUZ__T9__lambda2TSQBb4TestZQvFNaNbNfQtZDFNbNiZv in test.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: linker exited with status 1


to use without {}, it work as expect.

Is there a way to avoid this GC with {}, because we need multi line here.

Without the brackets it is inferring to not have state and hence is a function. But with the brackets it is assuming there is state required and hence has to allocate. Without manually allocating said state (not what you want), you cannot do this.

Reply via email to