Inversion of conditional compilation statements

Johannes Miesenhardt johannesmiesenhardt at gmail.com
Sat Dec 2 13:16:26 UTC 2023


Hello,
I am trying to learn D and I have stumbled upon an issue
Consider this code:
```d
import std.stdio;

//version = Test;

int main() {
         version (Test) {
                 writeln("Hello, world!");
         }
         return 0;
}
```

This compiles, however what if we want to turn the version 
statement around?
I first expected `version (!Test)` to work, but it doesn't since 
the grammar says:
```
VersionCondition:
     version ( Identifier )
     version ( unittest )
     version ( assert )
```

We are using the first way, the one with the Identifier.
The reason inverting works with if-statements is because they 
take an "Expression".

I see the way why it doesn't work, but I think it should. 
Considering that
`version (Test) {} else {`
works without any issue but looks very ugly.

Can somebody explain if this is an intended decision or what I 
should do instead of using my ugly replacement?


More information about the Digitalmars-d-learn mailing list