In article <X8*****************@read1.cgocable.net>
philipx <ak***@cogeco.ca> wrote:
IMO, you can freely choose between "#ifdef XYZ" and "#if defined(XYZ)", with
one exception, you cannot test for more than one thing in a single
"#ifdef".
Right.
Also, as a side note, the parentheses are not required when using
the "defined" pseudo-keyword (it is really just a magic identifier,
rather than a keyword, since keywords do not exist in these phases
of translation):
#ifdef X
#if defined(X)
#if defined X
are all synonymous.
consider the following, it's better to use "#if defined" than "#ifdef":
/* Test for the support of C99 Standard */
#if defined(__STDC_VERSION__) && __STD_VERSION__ > 199901L
/* ...something legal in C99 only */
This test is a little odd, because if __STDC_VERSION__ is not
defined, the test:
#if __STDC_VERSION__ > 199901L
is entirely legal and "means" the same thing as:
#if 0 > 199901L
which is of course false. In preprocessor expressions, undefined
identifiers *must* be replaced with 0. This is why:
#if sizeof(int) == 4
*must* produce a diagnostic, because -- assuming you have not done
something silly like "#define sizeof" -- it is syntactically the
same as:
#if 0(0) == 4
Once the required diagnostic has been emitted, a C compiler can go
back and "notice" that "sizeof" is not only not-defined but will
also become a valid keyword later, and then figure out that you
want it to act as though sizeof is allowed in preprocessor expressions.
A suitable diagnostic, for a smart compiler that does this, might
be something annoying like:
foo.c, line 123: warning: I handle "sizeof" the way you mean it
here, because "I M SMRT", but ANSI/ISO C compilers are not
required to, so your code may not work on other systems.
Of course, if you do "#define sizeof" -- e.g.:
#define sizeof(x) 3
#if sizeof(int) == 4
#undef sizeof
-- then other conditions apply.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it
http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.