digitalmars.D - Re: Defining a version after it's tested for
- Jason House <jason.house gmail.com> May 22 2009
- Robert Clipsham <robert octarineparrot.com> May 22 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.
May 22 2009
Jason House wrote:I wonder if a compiler patch to loosen the restrictions would be accepted. Something like what you tried should be trivial to support.
I doubt it's trivial to support... depending on when it's evaluated the version may or may not be set when it's checked, which is likely to cause confusion later on.
May 22 2009