Zero-cost version-dependent function call at -O0.

Johan Engelen via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jun 26 10:47:35 PDT 2017


On Sunday, 25 June 2017 at 23:02:28 UTC, Adam D. Ruppe wrote:
>
> That'd be kinda tricky because the arguments would still be 
> liable to be evaluated...

Well..
I guess someone might argue that's a mis-feature of my 
preprocessor example:  "foo(i++)" may not do what you want.  (So 
the C code would have to do "(void)param" for all params, to 
ensure evaluation and avoid compiler warning? =))

So I think I got things to work with inline IR! ^_^

https://godbolt.org/g/HVGTbx
```
version(none) {
   void foo(int a, int b, int c) { /*...*/ };
} else {
   pragma(LDC_inline_ir) R __ir(string s, R, P...)(P);
   alias foo = __ir!(`ret i32 0`, int, int, int, int);
}

void bar()
{
    int a;
    foo(a++,2,3);
}
```

-Johan


More information about the Digitalmars-d-learn mailing list