Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

DCL01-C-EX2: A temporary variable within a new scope inside of a macro can override an identifier in a containing scope. This However,this exception does not apply to to the arguments of the macro itself.

Code Block
bgColor#ccccff
langc
#define SWAP(type, a, b) do { type tmp = a; a = b; b = tmp; } while(0)
 
void func(void) {
  int tmp = 100;
  int a = 10, b = 20;
  SWAP(int, a, b); /* Hidden redeclaration of tmp is acceptable */
  SWAP(int, tmp, b); /* NONCOMPLIANT: Hidden redeclaration of tmp clashes with argument */
}

Risk Assessment

Reusing a variable name in a subscope can lead to unintentionally referencing an incorrect variable.

...