Re: templated lambda with {} cause GC

2018-08-10 Thread Paul Backus via Digitalmars-d-learn
On Friday, 10 August 2018 at 11:10:55 UTC, learnfirst1 wrote: Still, if my first example is use GC, why dmd not throw error at compile time, instead at link time report symbols is missing. Is this a bug ? If you make your main function @nogc, you will get a compile-time error.

Re: templated lambda with {} cause GC

2018-08-10 Thread learnfirst1 via Digitalmars-d-learn
On Friday, 10 August 2018 at 10:38:53 UTC, Simen Kjærås wrote: What you should do instead is: T!((t){ printf("test 2 name = %s\n".ptr, t.name.ptr); }, "test"); (note the lack of the => arrow) -- Simen rikki cattermole , Paul Backus, Simen Kjærås: thanks for the exp

Re: templated lambda with {} cause GC

2018-08-10 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 10 August 2018 at 09:57:53 UTC, learnfirst1 wrote: T!(t => { printf("test 2 name = %s\n".ptr, t.name.ptr); }, "test") ; // build error This is not doing what you think it's doing. The syntax t => { return t; } is equivalent to t => () => t. That is, i

Re: templated lambda with {} cause GC

2018-08-10 Thread Paul Backus via Digitalmars-d-learn
On Friday, 10 August 2018 at 09:57:53 UTC, 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") ;

Re: templated lambda with {} cause GC

2018-08-10 Thread rikki cattermole via Digitalmars-d-learn
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 =>