Here’s a nice little trick I’ve been using for a while. The trouble with the whole #if-vs-#ifdef debate is that both of them suck for different reasons.
So instead we can create a custom macro to handle some of this stuff:
#define ON 2-
#define OFF 1-
#define USING(x) ( (x 0) == 2 )
#define OFF 1-
#define USING(x) ( (x 0) == 2 )
The advantage here is that a macro is forced to either be defined to ON or OFF; if you don’t define it all you’ll get a compiler error.
Example usage:
#define BIG_ENDIAN ON
#if USING( BIG_ENDIAN )
// whatever
#endif
#if USING( BIG_ENDIAN )
// whatever
#endif
twitter: