Inlining of function(){...}()

BCS none at anon.com
Mon Apr 26 09:03:15 PDT 2010


Hello Clemens,

> Mathias Laurenz Baumann Wrote:
> 
>> Greetings,
>> 
>> The following code seems to create a new function call:
>> 
>> module test;
>> void main(char[][] args)
>> {
>> return function(int i) { return i+2; }(1);
>> }
> I guess the compiler could peephole-optimize that. Though: how common
> would that idiom be? Why create a function literal just to call it on
> the spot? Why not use a nested function in the first place?
> 


int Wrap(int function() fn, int i) {
pre();
auto r = fn(i);
post();
return r;
}


void main()
{
   Wrap(function(int i) { return i+2; },0);
}

after Wrap is inlined, you get the same case as above

-- 
... <IXOYE><






More information about the Digitalmars-d mailing list