www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Version reading material

reply jicman <jicman_member pathlink.com> writes:
Greetings, folks!

I've read the versioning subject found on the D html pages, but I need to
understand versioning.  Any web sites out there?

thanks.

josé
Feb 24 2005
parent reply Derek Parnell <derek psych.ward> writes:
On Fri, 25 Feb 2005 03:50:36 +0000 (UTC), jicman wrote:

 Greetings, folks!
 
 I've read the versioning subject found on the D html pages, but I need to
 understand versioning.  Any web sites out there?
Versioning is very staight forward in D. For example: 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 ... // 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. version(2) { // code here only gets compiled if the version has been // set to 0, 1, or 2. } To get this effect into action, invoke dmd thus ... dmd myapp -version=2 It can also be used to 'comment out' code ... version(none) { // this code is now commented out } This is useful 'cos it is easy to nest versions to make commenting out code easier. version(none){ FuncA(); version(none) { FuncB(); } } -- Derek Melbourne, Australia 25/02/2005 2:53:28 PM
Feb 24 2005
next sibling parent jicman <jicman_member pathlink.com> writes:
In article <12kzqpm2n6xm3.15ny3m5pkhnsk.dlg 40tude.net>, Derek Parnell says...
On Fri, 25 Feb 2005 03:50:36 +0000 (UTC), jicman wrote:

 Greetings, folks!
 
 I've read the versioning subject found on the D html pages, but I need to
 understand versioning.  Any web sites out there?
Versioning is very staight forward in D. For example: 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 ... // 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. version(2) { // code here only gets compiled if the version has been // set to 0, 1, or 2. } To get this effect into action, invoke dmd thus ... dmd myapp -version=2 It can also be used to 'comment out' code ... version(none) { // this code is now commented out } This is useful 'cos it is easy to nest versions to make commenting out code easier. version(none){ FuncA(); version(none) { FuncB(); } } -- Derek Melbourne, Australia 25/02/2005 2:53:28 PM
thank you, Derek.
Feb 24 2005
prev sibling next sibling parent reply "Lionello Lunesu" <lionello.lunesu crystalinter.remove.com> writes:
Hi..

 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.

   version(2)
   {
      // code here only gets compiled if the version has been
      // set to 0, 1, or 2.
   }
This felt a bit funny to me when I read it: it means that if I want to compile "version 1" it'll include stuff from "version(2){...}", so I checked the doc: version(n) { } // add in version code if version level is >= n So version(1) gets included for version>=1, which makes more sense :-) Lionello.
Feb 25 2005
parent Derek <derek psych.ward> writes:
On Fri, 25 Feb 2005 10:48:53 +0200, Lionello Lunesu wrote:

 Hi..
 
 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.

   version(2)
   {
      // code here only gets compiled if the version has been
      // set to 0, 1, or 2.
   }
This felt a bit funny to me when I read it: it means that if I want to compile "version 1" it'll include stuff from "version(2){...}", so I checked the doc: version(n) { } // add in version code if version level is >= n So version(1) gets included for version>=1, which makes more sense :-)
Duh! Of course. I don't know what I was thinking ;-) -- Derek Melbourne, Australia
Feb 25 2005
prev sibling parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Derek Parnell wrote:

I've read the versioning subject found on the D html pages, but I need to
understand versioning.  Any web sites out there?
Versioning is very staight forward in D.
That might be, but it has a number of outstanding issues...
 For example:
 
  version(XX)
  {
      // code here gets compiled if version XX is active
  }
If you want to do stuff if XX is *not* set, you need to do: version(XX) {} else { ... } There's a patch for version(!XX), but it has not been accepted, nor commented, just yet ?
  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.
      }
 }
If you need to do stuff if !(XX and YY), things get more interesting. (a common example here being version(D_InlineAsm) and version(X86)...) The most straightforward method is to set up a new temp version: version(D_InlineAsm) { version(X86) { version = UseX86Asm; } }
 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
 ...
An expanded list is at: (the original page only shows DMD versions) http://www.prowiki.org/wiki4d/wiki.cgi?DocComments/Version Note the important casing differences here: "Windows" vs. "linux"
    // Set Posix version active if either linux or darwin is active.
    version(linux) version=Posix;
    version(darwin) version=Posix;
Sigh, this particular example is just reminding of another sad story... And it should probably be:
    version(linux) version=Posix;
    version(darwin) version=Posix;
    version(freebsd) version=Posix;
    version(cygwin) version=Posix;
    version(solaris) version=Posix;
Possibly other systems, yet to come ? (but this is a different topic)
 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.
 
    version(2)
    {
       // code here only gets compiled if the version has been
       // set to 0, 1, or 2.
    }
 
 To get this effect into action, invoke dmd thus ...
 
    dmd myapp -version=2
 
Sadly one can't have "versions of versions", which means it can't be used like #if VERSION > 42 could. But you can have one global version number, and one debug version number: "debug(3)" (debug level >= 3)
 It can also be used to 'comment out' code ...
 
    version(none) {
      // this code is now commented out 
    }
 
 This is useful 'cos it is easy to nest versions to make commenting out code
 easier.
Usually one uses /+ +/ for commenting out code, but version(none) and version(all) are the matches for #if 0 and #if 1, as the C preprocessor uses... **** Conditional compilation in general also has some non-technical maintenance issues, and some languages like Java do not support it for that reason - like other stuff that "might be dangerous", like pointers, gotos, native code, and all other adult C topics. ;-) For instance, "assert" statements in Java are always left in and triggered at runtime: http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html#design-faq-enable-disable Similarly, debug versions are usually a global boolean: "if (debug) { }" As usual, D is more towards the C end of doing things. Or in the middle? --anders
Feb 25 2005