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

Johan Engelen via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 25 08:58:48 PDT 2017


How would you solve this problem: do an optional function call 
depending on some version(X). If version(X) is not defined, there 
should be no call and no extra code at -O0.

```
{
...
    foo();  // either compiles to a function call, or to _nothing_.
...
}
```

In C, you could do something like:
```
#if X
   void foo() {......}
#else
   #define foo()
#endif
```

How would you do this in D?

I can think of `mixin(foo())` but there is probably a nicer way 
that preserves normal function calling syntax.

Cheers,
   Johan



More information about the Digitalmars-d-learn mailing list