Water Cooler v2 wrote:
Sorry if this is a foolish question, but here it is.
I see things like
#ifndef STDC
...blah
#endif
#ifdef WIN32
...blah
#endif
in open source projects but I do not see where they actually define
these symbols WIN32 and STDC. I know what the #ifdef and #ifndef
preprocessor directives mean. I want to know how these symbols like
STDC and WIN32 are chosen. Are they some pre-defined symbols that
individual compilers expect? Or are they included when building the
project? What gives?
A few preprocessor symbols like __STDC__ (not STDC) are
defined by all Standard-conforming C compilers. Others may
be defined by particular compilers, but the only place to
learn about them is from the compilers' documentation. Many
compilers allow preprocessor symbols to be defined at the time
the compiler is invoked (often by means of command-line options);
you'll need to check the build scripts or Makefiles or whatever
other machinery the project uses.
As it happens, a compiler that predefines WIN32 (without
being provoked by a command-line option or something) is not
Standard-conforming. The identifier WIN32 should be available
for any use the programmer cares to make of it. The following
is a strictly conforming program, and a compiler whose predefined
names clash with anything here is non-conforming:
#include <stdio.h>
#include <stdlib.h>
#define SPARC EXIT_SUCCESS
#define I386 EXIT_FAILURE
int main(int WIN32, char **STDC) {
char UNIX[] = "Hello, world!";
int VAX = puts(UNIX);
return VAX == EOF ? SPARC : I386;
}
--
Eric Sosman
es*****@acm-dot-org.invalid