Re: Macro to cause build failure if parameter not defined?
- From: Eric Sosman <esosman@xxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 26 Jun 2008 09:26:54 -0400
skillzero@xxxxxxxxx wrote:
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 think
#define HAS_FEATURE(macro) ( (macro) / defined(macro) )
.... might suit you, if you don't mind an uninformative or maybe
even misleading diagnostic.
--
Eric Sosman
esosman@xxxxxxxxxxxxxxxxxxxx
.
- Follow-Ups:
- Re: Macro to cause build failure if parameter not defined?
- From: Peter Nilsson
- Re: Macro to cause build failure if parameter not defined?
- References:
- Macro to cause build failure if parameter not defined?
- From: skillzero@xxxxxxxxx
- Macro to cause build failure if parameter not defined?
- Prev by Date: Re: single if vs if else
- Next by Date: types, variable names and fields
- Previous by thread: Re: Macro to cause build failure if parameter not defined?
- Next by thread: Re: Macro to cause build failure if parameter not defined?
- Index(es):
Relevant Pages
|