Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#ifdef query and clarification needed

Tags:

c

I see constructions like:

#ifdef FOO || defined BAR
...
#endif

and compiler's complaints "warning: extra tokens at end of #ifdef directive", obviously it should be:

#if defined FOO || defined BAR
...
#endif

Does the standard explicitly say so? Could you point at the relevant part?

like image 549
Mark Avatar asked Feb 16 '12 16:02

Mark


1 Answers

In C99, 6.10 Preprocessing directives, paragraph 1 is Syntax:

if-group:
# if constant-expression new-line groupopt
# ifdef identifier new-line groupopt
# ifndef identifier new-line groupopt

It shows your first construction with #ifdef is incorrect as only an identifier can follow the #ifdef, a constant expression is not allowed.

like image 169
ouah Avatar answered Nov 16 '22 15:11

ouah