= Conditional Compilation (a/k/a Versioning) Examples = * BuiltInVersionsExample * CompileTimeBuiltInVersionsExample * CompileTimeVersioningExample * VersionsToStoreMultipleProgramInOneFileExample == Examples That Use Version in Other Categories == * DateLocalizationUsingVersionExample * LocalesExample == Versioning is very straight forward in D == ''(adapted from [http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=17398 NG:digitalmars.D/17398])'' Versioning is very straight forward in D. For example: {{{ #!d version(XX) { // code here gets compiled if version XX is active } version(YY) { // code here gets compiled if version YY is active version(XX) { // Both YY and XX must be active for this stuff to compile. } } }}} You can set the versions by the command line -version= switch. Some versions are '''built-in''' and are already active. You can also set versions during the compile process from within your code... {{{ #!d // Set Posix version active if either linux or darwin is active. version(linux) version=Posix; version(darwin) version=Posix; }}} You can also set version '''levels'''. This means that the code will only compile if the current version level is greater than or equal to the one specified in the code. The assumption is that higher versions include code that applied to earlier versions (i.e. Compiling for version 4 must also include stuff that was created for version 3 and earlier). {{{ #!d version(2) { // code here only gets compiled if the version has been // set to 2 or higher. } }}} To get this effect into action, invoke dmd thus ... {{{ dmd myapp -version=2 }}} It can also be used to '''comment out''' code ... {{{ #!d version(none) { // this code is now commented out } }}} This is useful because it is easy to nest versions to make commenting out code easier. {{{ #!d version(none){ FuncA(); version(none) { FuncB(); } } }}} == More Information == See: [http://www.digitalmars.com/d/version.html Conditional Compilation] in the D Specification.