www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - version() used in multiple special cases?

reply AEon <aeon2001 lycos.de> writes:
On

http://www.dsource.org/tutorials/index.php?show_example=117

I found this interesting example of version() use

<code>
// By Joey Peters

// pass -version=free to dmd
version(Free) {
  version = FeatureA;
} else {
  version = FeatureA;
  version = FeatureB;
}

void main() {
  // every version has this.
  version(FeatureA) {
    printf("Hello world!");
  }
  // only the non free has this
  version(FeatureB) {
    printf("Deluxe!");
  }
}
</code>

I but from reading die above I get the feeling you also ways need to 
place version + else. What I would be looking for is to be able to do 
this...


...code...

version(debug)
{
	writefln...
}

...code...

version(debugging2)
{
	writefln...
}

...code...

and be able to selectively turn those blocks on and off.

Would -version=debug compile my code, plus turn on the debug version 
section, but not the debugging2 section. Dito for -version=debugging2?

Could I then group them

version(AllDebug) {
  version = debug;
  version = debugging2;
} else {
}

I.e. that with -version=AllDebug I could turn on all debugging, and by 
not defining a -version, no debug code would be in the compile?


AEon
Mar 31 2005
parent AEon <aeon2001 lycos.de> writes:
AEon wrote:
 I but from reading the above I get the feeling you always need to 
 place version + else. What I would be looking for is to be able to do 
 this...
 
 ....code...
 
 version(debug)
 {
     writefln...
 }
 
 ....code...
 
 version(debugging2)
 {
     writefln...
 }
 
 ....code...
 
 and be able to selectively turn those blocks on and off.
 
 Would -version=debug compile my code, plus turn on the debug version 
 section, but not the debugging2 section. Dito for -version=debugging2?
Just tested this, the above already works as expected (hoped for), i.e. you do not need to define the "default" code in an else{} of version. So far so good.
 Could I then group them
 
 version(AllDebug) {
  version = debug;
  version = debugging2;
 } else {
 }
 
 I.e. that with -version=AllDebug I could turn on all debugging, and by 
 not defining a -version, no debug code would be in the compile?
This does not work though. Is there any way to group all the versions in one new version tag? AEon
Mar 31 2005