Why doesn't this work (It's failing the assert...that I don't want it to execute)?
#define OS_MACOSX 0
#if defined(OS_MACOSX)
fructose_assert(1==2);
#endif
Why doesn't this work (It's failing the assert...that I don't want it to execute)?
#define OS_MACOSX 0
#if defined(OS_MACOSX)
fructose_assert(1==2);
#endif
Because you're using the wrong test.
OS_MACOSX
IS defined... to 0
. You asked if it is defined. Ask instead if it is set:
#if OS_MACOSX
fructose_assert(1==2);
#endif
If it is defined to something that evaluates to zero, or not defined at all, the #if
will skip over the code. Any non-zero value, and the #if
condition is met and the code is compiled.
See this related question: Why do people use #ifdef for feature flag tests?