Defining a version after it's tested for
Robert Clipsham
robert at octarineparrot.com
Thu May 21 07:45:24 PDT 2009
I recently came across this:
version( BackendFoo ) {}
else version( BackendBar ) {}
else version( BackendCar ) {}
else
{
pragma( msg, "Warning: backend version undefined" );
pragma( msg, "Attempting to guess backend" );
version( Windows )
{
version = BackendFoo;
pragma( msg, "Selected the Foo backend." );
}
else version(...)
{ /* You get the idea */ }
}
However, when trying to compile I get the following error:
Error: version BackendFoo defined after use
What is the reasoning behind this? It could be extremely useful to have
this functionality. The only reason I can think of for doing this is
that this code could be evaluated after modules that depend on the
version being defined, causing it not to work. Surely there would be a
way around that?
If it's not possible to fix this, what way would you recommend I get
around this? The only idea I've come up with so far is to do:
else
{
static assert( false, "Please compile with
-version=Backend(Foo|Bar|Bar)" );
}
Which is less than optimal.
More information about the Digitalmars-d
mailing list