Defining a version after it's tested for

Jason House jason.house at gmail.com
Fri May 22 05:54:56 PDT 2009


Robert Clipsham Wrote:

> 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.

I wonder if a compiler patch to loosen the restrictions would be accepted. Something like what you tried should be trivial to support.



More information about the Digitalmars-d mailing list