Conditional compilation inside asm and enum declarations

Walter Bright newshound1 at digitalmars.com
Tue Jul 14 14:52:22 PDT 2009


Leandro Lucarella wrote:
> The same goes for version (!X) ..., I think it should be available, there
> are cases when the use is valid and you have to do artificial hacks like
> version (X) else .... It's like Java not having functions or global
> variable. You're just annoying people that know what they're doing to
> "protect" the idiots (which can go and use static methods and variables
> anyways; or version (X) else ...).

It's not about protecting idiots. It's about making the better way to do 
things the easier and more natural way, and making the worse more difficult.

In C++,

    int a[5];

is the wrong way, and:

    std::vector<int>(5) a;

is the right way. C++ makes the right way ugly and hard. I'd like to 
reverse that.

All languages have some characteristics of "you shouldn't be allowed to 
do that", the problem is where the line is drawn.

I have long, long experience with #ifdef's. I know how convenient it is 
to just plop those things in, like your first hit of heroin. I know how 
justifiable just that one little old #ifdef is. Then you add in another, 
and another, and another, and another, and eventually wonder how you 
wound up with such an impenetrable thicket of awfulness. My own code 
gets like that (despite my knowing better) and just about every long 
lived piece of C/C++/asm code I've run across.

I do the same as you, running the preprocessor independently on C code 
to figure out what's happening. That, however, would be problematic with 
D as it doesn't have a preprocessor. You'd have to build a separate tool 
to do it.



More information about the Digitalmars-d mailing list