Defining a version after it's tested for

Don nospam at nospam.com
Fri May 22 01:48:28 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?

Versions are like in functional programming, they are NOT variables. 
Once you've tested the existence of a non-existent version identifier, 
you've implicitly declared it.
When there was a discussion about 'version' some time back, I made a 
proposal which (among other things) would require you to explicitly 
state that a particular version identifier is set from the command line; 
that would make this case clearer.



More information about the Digitalmars-d mailing list