Improving version(...)

bearophile bearophileHUGS at lycos.com
Tue Oct 19 15:50:12 PDT 2010


Jonathan M Davis:

> On Monday, October 18, 2010 12:24:48 Don wrote:
> > And currently, you can make a typo like:
> > version(Linix) {}
> > and it compiles happily. I don't like that. Especially when we have
> > builtin names like D_Inline_Asm_X86_64!
> 
> The real question is how to cleanly fix that. A version is defined only if it's in 
> use, so it can't do like variable declarations do and complain that the version 
> wasn't declared. You could even be stupid enough to declare your own version 
> D_Inline_Asm_X86_65, so it's not even like the compiler can necessarily complain 
> when a version declaration uses a version which is almost the same as a correct 
> one but not quite (since you could just not be compiling with that version 
> declared at the moment).

If built-in versions are inside some kind of enum or namespace, the compiler can tell apart the built-in ones from all the other ones, so if you write:
version(std.D_Inline_Asm_X86_65)
The compiler will complain that doesn't exists among the standard ones.

If you want to use your own ones you just don't use the "std." prefix:
version(myFoo)

Bye,
bearophile


More information about the Digitalmars-d mailing list