Function-like Macro Hygiene

We need to use function-like macro with care to avoid writing a confusing macro and/or resulting in an unexpected behaviour. Use function-like macro only if it satisfys three conditions:

  • Only evaluate each argument once. (forbid unexpected behavoiur from incrementation or decrementation)
  • Parenthesise all arguments.
  • There is no hidden effects (side effects or unexpected control flow).
Links to this page
#metaprogramming #c #hygiene