Robert Fraser wrote: > David Ferenczi wrote: >> == Quote from Sergey Gromov ([email protected])'s article >>> Sun, 18 Jan 2009 22:28:12 +0100, Hoenir wrote: >>>> The D_Version2 version identifier doesn't work properly for me. >>>> Tried compiling with dmd 1.039. D_Version2 is set even if I pass -v1 to >>>> it. >>>> >>>> Is this a bug or am I doing something wrong? >>> Works for me. >>> It's hard to tell if you're doing something wrong until you post your >>> test code. >>> ----8<------ test.d >>> version(D_Version2) >>> { >>> pragma(msg, "v2"); >>> } >>> else >>> { >>> pragma(msg, "v1"); >>> } >>> ----8<------ >>>> dmd -c test.d >>> v1 >> >> The behaviour is a bit ambigous, since in compile time every version >> block gets interpreted! So you cannot put D2 only code in the >> version(D_Version2) {} block, if you want to compile your source with D1. >> >> I don't know if it's a bug or a feature. >> >> Regards, >> David > > This has been discussed many times over. It's a "feature" according to > Walter, and there's some sense to it (since D code is supposed to be > parseable without doing semantic analysis, and versions can require > arbitrary ammounts of semantic analysis (like CTFE) to determine). If > you want to have D2 code you need to use a mixin: > > version(D_Version2) { > mixin("const(char)[] x;"); > } else { > char[] x; > } > > Note that the -v1 switch reverts to the (rather arbitrary) D version > 1.00, while new D features were being added through (I think) 1.014.
Many thanks for your answer. I should have missed this discussion. I still think, that it should be possible to skip the code blocks, which are behind not met version conditons. Maybe an extra compiler switch? Do I presume correctly that in case of using a mixin the literal won't be interpreted, and that's why it doesn't cause any problem?
