Compilation constants
bearophile
bearophileHUGS at lycos.com
Wed Nov 11 05:50:48 PST 2009
In a C program I have a numeric constant SIZE (that is in [1,32]), that I can define when I compile the code, like this:
gcc -DSIZE=14 ...
How can I do the same thing in D? The solution I have found is to put in the D code:
version(B1) const SIZE = 1;
version(B2) const SIZE = 2;
version(B3) const SIZE = 3;
version(B4) const SIZE = 4;
...
version(B14) const SIZE = 14;
...
And then compile the D program with:
dmd -version=B14 ...
Or:
ldc -d-version=B14 ...
Do you know nicer ways to do this in D? (if there are no nicer ways, is this simple feature worth adding to D?)
Thank you, bye,
bearophile
More information about the Digitalmars-d-learn
mailing list