S
skillzero
Is there a way to cause a compile/preprocessor error in a macro if a
preprocessor symbol is not defined? I want to do the equivalent of
this in a macro:
#if( !defined( SOME_FLAG ) )
#error not defined
#endif
What I want is a way to test if a feature flag is defined to 1 such
that if it's not defined at all (as opposed to defined to 0), I'll get
a compile error. This is to catch cases where people test for a
feature flag without including the right header file, using the right
compile flags, or they just typed it wrong. I want to use it like
this:
#if( HAS_FEATURE( FEATURE_X ) )
... do something if FEATURE_X is defined
#endif
I'll #define FEATURE_X to 1 if supported or #define FEATURE_X to 0 if
not suported. If not defined at all, I want to generate a compile
error.
I know some compilers have options to warn about #if used with
undefined symbols, but I wanted something more portable.
preprocessor symbol is not defined? I want to do the equivalent of
this in a macro:
#if( !defined( SOME_FLAG ) )
#error not defined
#endif
What I want is a way to test if a feature flag is defined to 1 such
that if it's not defined at all (as opposed to defined to 0), I'll get
a compile error. This is to catch cases where people test for a
feature flag without including the right header file, using the right
compile flags, or they just typed it wrong. I want to use it like
this:
#if( HAS_FEATURE( FEATURE_X ) )
... do something if FEATURE_X is defined
#endif
I'll #define FEATURE_X to 1 if supported or #define FEATURE_X to 0 if
not suported. If not defined at all, I want to generate a compile
error.
I know some compilers have options to warn about #if used with
undefined symbols, but I wanted something more portable.