2012-02-16 184 views
5

我看到這樣的結構:#ifdef來查詢和澄清需要

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

和編譯器的投訴,「警告:額外的令牌在#ifdef指令的終結」,顯然應該是:

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

不該標準明確表示如此?你能指出相關部分嗎?

+4

我一直認爲'#ifdef'只適用於單個符號。我讀爲',如果符號被定義...'。 – 2012-02-16 16:23:13

回答

5

在C99,6.10預處理指令,第1段是語法:

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

它顯示您的與#ifdef第一構造是不正確,僅作爲標識符可以按照#ifdef,常量表達式是不允許的。