Versions Compared

Key

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

...

Code Block
bgColor#FFCCCC
#define assign(uc1, uc2, uc3, uc4, val) \
  uc1##uc2##uc3##uc4uc1##uc2 = val;

int \u0401\u0401\u0401\u0402;
assign( \u0401u04, \u0401, \u0401, \u040201, 4);

Implementation Details

This code compiles and runs on Microsoft Visual C++ 2008, assigning 4 to the variable as expected.

GCC 4.3 on Linux refuses to compile this code; it complains of a "stray \", referring to the universal character fragment in the invocation of the assign macroWhile noncompliant, this code does produce the expected behavior; that is, it assigns the variable the value 4 on both MSVC 2008, and on Linux/GCC 4.3, when compiled with -std=c99 -fextended-identifiers.

Compliant Solution

This code solution is compliant.

Code Block
bgColor#ccccff
#define assign(ucn, val) ucn = val;

int \u0401\u0401\u0401\u0402;
assign( \u0401\u0401\u0401\u0402, 4);

Risk Assessment

Creating a universal character name through token concatenation results in undefined behavior.

...