Versions Compared

Key

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

The C Standard supports universal character names that may be used in identifiers, character constants, and string literals to designate characters that are not in the basic character set. The universal character name \Unnnnnnnn designates the character whose eight8-digit short identifier (as specified by ISO/IEC 10646) is nnnnnnnn. Similarly, the universal character name \unnnn designates the character whose four4-digit short identifier is nnnn (and whose eight8-digit short identifier is 0000nnnn).

Subclause The C Standard, 5.1.1.2, paragraph 4 , of the C Standard  [ISO/IEC 9899:2011], says,

If a character sequence that matches the syntax of a universal character name is produced by token concatenation (6.10.3.3), the behavior is undefined.

See also undefined behavior 3.

In general, avoid universal character names should be avoided in identifiers unless absolutely necessary. The basic character set should suffice for almost every identifier.

Noncompliant Code Example

...

Code Block
bgColor#FFCCCC
langc
#define assign(uc1, uc2, val) uc1##uc2 = val;

void func(void) {
  int \u0401;
  /* ... */
  assign(\u04, 01, 4);
  /* ... */
}

...

GCC 4.8.1 on Linux refuses to compile this code; it complains of a "stray \," referring to the universal character fragment in the invocation of the assign macro.

Compliant Solution

This code solution is compliant because it does not form an identifier through concatenation involving compliant solution uses a universal character name but does not create it by using token concatenation:

Code Block
bgColor#ccccff
langc
#define assign(ucn, val) ucn = val;
 
void func(void) {
  int \u0401;
  /* ... */
  assign(\u0401, 4);
  /* ... */
}

...

[ISO/IEC 10646-2003] 
[ISO/IEC 9899:2011]Subclause 5.1.1.2, "Translation Phases"

...