Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code blocks between #if 0 and #endif must have paired double quotes?

Tags:

c

int main(void)
{
    #if 0
    something"
    #endif
    return 0;
}

A simple program above generates a warning: missing terminating " character in gcc. This seems odd, because it means that the compiler allow the code blocks between #if 0 and endif have invalid statement like something here, but not double quotes " that don't pair. The same happens in the use of #ifdef and #ifndef.

Real comments are fine here:

int main(void)
{
    /*
    something"
    */
    return 0;
}

Why? And the single quote ' behave similarly, is there any other tokens that are treating specially?

like image 308
Yu Hao Avatar asked Jun 22 '13 04:06

Yu Hao


1 Answers

See the comp.Lang.c FAQ, 11.19:

Under ANSI C, the text inside a "turned off" #if, #ifdef, or #ifndef must still consist of "valid preprocessing tokens." This means that the characters " and ' must each be paired just as in real C code, and the pairs mustn't cross line boundaries.

like image 164
Kevin Avatar answered Sep 25 '22 09:09

Kevin