I am porting some code to 8051 and the existing code uses #define to determine whether or not some functionality is available i.e. ....
#define HAVE_STRING_H . . . . #ifndef HAVE_STRING_H #include <string.H #else #include <homegrown/string.h> #endif
#define HAVE_STRING_H
#define HAVE_STRING_H 1
#ifdef HAVE_STRING_H
#if HAVE_STRING_H
I'd never realised [undefined substituted with 0] was supposed to happen Good ol' K&R behavior. It helps contribute to the popular trap when people try to use the conditionals with nice readable string values instead of integers: -DPLATFORM=EVAL #if PLATFORM == EVAL #elif PLATFORM == SIM #endif Works like a charm, since PLATFORM becomes EVAL, and then EVAL on both sides of the first == becomes 0. 0 == 0, so off you go with the first branch, even if you -DPLATFORM=SIM. A warning can be a good thing. (You can actually make this work if you #define a series of constants for EVAL, SIM, etc., in a header, and are sure to include that header.)