Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changes between Version 5 and Version 6 of VersioningCategory

Show
Ignore:
Author:
jcc7 (IP: 192.149.244.9)
Timestamp:
03/15/07 15:33:10 (11 years ago)
Comment:

moved example from Wiki4D

Legend:

Unmodified
Added
Removed
Modified
  • VersioningCategory

    v5 v6  
    1212 
    1313 
     14== Versioning is very straight forward in D == 
     15 
     16''(adapted from [http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=17398 NG:digitalmars.D/17398])'' 
     17 
     18Versioning is very straight forward in D. 
     19 
     20For example: 
     21{{{ 
     22#!d 
     23version(XX) 
     24{ 
     25    // code here gets compiled if version XX is active 
     26} 
     27 
     28version(YY) 
     29{ 
     30   // code here gets compiled if version YY is active 
     31   version(XX) { 
     32      // Both YY and XX must be active for this stuff to compile. 
     33   } 
     34} 
     35}}} 
     36You can set the versions by the command line -version= switch. 
     37 
     38Some versions are '''built-in''' and are already active. 
     39 
     40You can also set versions during the compile process from within your code... 
     41{{{ 
     42#!d 
     43// Set Posix version active if either linux or darwin is active. 
     44version(linux) version=Posix; 
     45version(darwin) version=Posix; 
     46}}} 
     47You 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). 
     48 
     49{{{ 
     50#!d 
     51version(2) 
     52{ 
     53   // code here only gets compiled if the version has been 
     54   // set to 2 or higher. 
     55} 
     56}}} 
     57To get this effect into action, invoke dmd thus ... 
     58{{{ 
     59dmd myapp -version=2 
     60}}} 
     61It can also be used to '''comment out''' code ... 
     62{{{ 
     63#!d 
     64version(none) { 
     65   // this code is now commented out  
     66} 
     67}}} 
     68This is useful because it is easy to nest versions to make commenting out code easier. 
     69{{{ 
     70#!d 
     71version(none){ 
     72   FuncA(); 
     73   version(none) { 
     74      FuncB(); 
     75   } 
     76} 
     77 
     78}}} 
     79 
     80 
    1481== More Information == 
    1582 
    16 See also: the [http://www.digitalmars.com/d/version.html D Specification]
     83See: [http://www.digitalmars.com/d/version.html Conditional Compilation] in the D Specification