This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Testing validity of macro arguments


Hi James,

Assuming that your macro is called "MagicFn" (with $dostuff$ doing the appropriate thing)...

  #define MagicFn(MacroParm) $dostuff$

...where you use the macro you can do this at invocation:

  #ifndef MyParm
  #error MyParm must be a macro
  #endif
  MagicFn(MyParm)

If, instead, you want to do something like this...
  #define MagicFn(MacroParm) \
  #ifndef MacroParm \
  #error MacroParm must be a macro \
  #endif \
  $dostuff$
... you can't do it in C/C++ with the C/C++ preprocessor.

The only way to do that is to run a PRE-preprocessor of your own devising.  You could write one that would be sufficient in Flex & Bison, or Perl, or sed.

HTH,
--Eljay



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]