Request assistance converting C's #ifndef to D
Andrew Edwards via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu May 12 15:51:17 PDT 2016
The following preprocessor directives are frequently encountered in C
code, providing a default constant value where the user of the code has
not specified one:
#ifndef MIN
#define MIN 99
#endif
#ifndef MAX
#define MAX 999
#endif
I'm at a loss at how to properly convert it to D. I've tried the following:
enum MIN = 0;
static if(MIN <= 0)
{
MIN = 99;
}
it works as long as the static if is enclosed in a static this(),
otherwise the compiler complains:
mo.d(493): Error: no identifier for declarator MIN
mo.d(493): Error: declaration expected, not '='
This however, does not feel like the right way to do thinks but I cannot
find any documentation that provides an alternative. Is there a better
way to do this?
Thanks,
Andrew
More information about the Digitalmars-d-learn
mailing list