Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C99, "Despite the name, a non-directive is a preprocessing directive."

What does the quoted footnote in the title mean? It's a footnote attached to 6.10.3p11

If there are sequences of preprocessing tokens within the list of arguments that would otherwise act as preprocessing directives,147) the behavior is undefined.

I checked up and found

A preprocessing directive consists of a sequence of preprocessing tokens that begins with a # preprocessing token that ...

and I didn't find the non-terminal non-directive matching that syntax. It can, but doesn't have to, start with a # preprocessing token. So wouldn't we have to say the following?

"Despite the name, a preprocessing directive is a non-directive."

Also, what is the purpose of that footnote?

like image 294
Johannes Schaub - litb Avatar asked Apr 15 '11 15:04

Johannes Schaub - litb


2 Answers

See http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_250.htm It is to clarify that

#define nothing(x) // Nothing    /* Case 1 */
nothing (
#nonstandard
)

is UB.

like image 149
AProgrammer Avatar answered Sep 28 '22 07:09

AProgrammer


My copy of C99 doesn't have that footnote (it's the original - do you have one with TR corrections applied?) but I think the idea is that if you have

# non-directive

inside a macro argument list, that's still undefined behavior.

It would have been better to make the <non-directive> production include the #, I think, it would simplify 6.10p3,4 as well as removing this confusion.

like image 37
zwol Avatar answered Sep 28 '22 07:09

zwol