Sabrina
Sabrina

Reputation: 1466

Single non-white-space characters in the C preprocessor

From the C11 Standard Draft N1570, §6.4/3:

[...] The categories of preprocessing tokens are: header names, identifiers, preprocessing numbers, character constants, string literals, punctuators, and single non-white-space characters that do not lexically match the other preprocessing token categories.69) If a ' or a " character matches the last category, the behavior is undefined. [...]

69) An additional category, placemarkers, is used internally in translation phase 4 (see 6.10.3.3); it cannot occur in source files.

(Emphasis mine.)

I cannot find a valid way to code a program containing a valid preprocessing token ".

Upvotes: 1

Views: 206

Answers (1)

rici
rici

Reputation: 241721

The text you highlighted says that if a ' or " is used in such a way that it would be a single non-whitespace character preprocessing token, then the program is invalid (i.e. "the behaviour is undefined"). So no self-respecting compiler will allow you do do that; compilers certainly don't have any obligation to do anything you might consider sensible with explicitly undefined behaviour.

Upvotes: 2

Related Questions