2013-07-20 31 views
0
預期的表達

我的代碼包含錯誤:#29:用C

#define READ_TAMPER_PIN() {((FIO2PIN & PIN_TAMPER) >> 12) ;} 

其中PIN_TAMPER又是一個宏

#define PIN_TAMPER  0x00001000; 
在頭文件中的一個

,並且它被稱爲主()之類

x = READ_TAMPER_PIN(); 

它提供了一個錯誤說「錯誤:#29:預期表達式」

什麼可能是我犯的錯誤?

+0

注:它的「錯誤:預期的表達」,在嵌入式C – YMJ

回答

3

宏中的大括號和分號錯了。使用:

#define READ_TAMPER_PIN() ((FIO2PIN & PIN_TAMPER) >> 12) 
+0

你的意思是{}括號? – YMJ

+0

你的意思是{}括號? 我以前的宏#define DIR_TAMPER_IN_PORT()\t {FIO2DIR&=〜PIN_TAMPER;} doesent給出了這樣的錯誤,但? – YMJ

+0

1.是的,我的意思是'{}'。 2.推測你沒有嘗試將'DIR_TAMPER_IN_PORT()'的結果賦值給一個變量。如果你這樣做,你會得到同樣的錯誤。 –

0

根據C99標準(§6.10.3#10)

形式的預處理指令

#限定標識符LPAREN標識符listopt)替換列表新行

#定義標識LPAREN ...)替換列表換行

#定義標識LPAREN標識符表,...)替換列表換行

defines a function-like macro with arguments, similar syntactically to a function call. The parameters are specified by the optional list of identifiers, whose scope extends from their declaration in the identifier list until the new-line character that terminates the #define preprocessing directive. Each subsequent instance of the function-like macro name followed by a ( as the next preprocessing token introduces the sequence of preprocessing tokens that is replaced by the replacement list in the definition (an invocation of the macro). The replaced sequence of preprocessing tokens is terminated by the matching ) preprocessing token, skipping intervening matched pairs of left and right parenthesis preprocessing tokens. Within the sequence of preprocessing tokens making up an invocation of a function-like macro, new-line is considered a normal white-space character.

+0

這個答案與OP的問題有什麼關係? –

+0

@CarlNorum只是爲了說明宏的正確語法。 – 0decimal0

+0

OP的宏語法很好,但。只是他使用'{}'不允許他想要做的任務發生。 –

相關問題