version and debug statements

Ameer Armaly ameer_armaly at hotmail.com
Thu May 11 13:23:10 PDT 2006


"Walter Bright" <newshound at digitalmars.com> wrote in message 
news:e3vple$1rp5$1 at digitaldaemon.com...
> Anders F Björklund wrote:
>> I'm still naively hoping for both of "version (Unix)"
>
> DMD supports Windows and Linux; Unix is neither. For a compiler which 
> targets the Unix operating system, it should set the Unix version.
>
>> and "version (!Windows)" to be defined and legal in D.
>
> In C and C++, I often see:
>
> #if !WIN32
>
> when what is really meant is:
>
> #if linux
>
> i.e. the former is almost always a bug waiting to happen (when someone 
> tries to compile for a third operating system). Versions should be "this 
> build is for this configuration" rather than "this build is not for that 
> configuration."
>
> One can also write:
> version (ThisFeature)
> {
> }
> else
> {
> version = ThatFeature;
> }
>
> ...
>
> version (ThatFeature)
> ...
>
> For an example of why D is this way, see the sources to the Hans Boehm 
> garbage collector, where the complex thicket of #if's makes it extremely 
> difficult to see exactly what is being compiled.
One situation I can see where this kind of functionality could be useful is 
where you want the default compiled behavior to execute a given block of 
code, but with a given version switch you want it taken out.  Rather than 
wrapping your prefered behavior in a version block, or putting in an empty 
version block which raises all sorts of questions, you could just say 
"Unless a given version specifier is defined, do this." 





More information about the Digitalmars-d mailing list