2013-07-20 58 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的宏语法很好,但。只是他使用'{}'不允许他想要做的任务发生。 –

相关问题