Re: Testing validity of macro arguments

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux