C语言 错误:#29:需要 C 中的表达式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17758887/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
error: #29: expected an expression in C
提问by YMJ
my code contains
我的代码包含
#define READ_TAMPER_PIN() {((FIO2PIN & PIN_TAMPER) >> 12) ;}
where PIN_TAMPERis again a macro-
哪里PIN_TAMPER又是一个宏——
#define PIN_TAMPER 0x00001000;
in one of the header file, and it is called in main() like
在其中一个头文件中,它在 main() 中被调用,如
x = READ_TAMPER_PIN();
it gives an error saying "error: #29: expected an expression"
它给出了一个错误,说“错误:#29:需要一个表达式”
what could be possible mistake that I'm making here??
我在这里犯了什么可能的错误?
回答by Carl Norum
The braces and semicolon in your macro are wrong. Use:
宏中的大括号和分号是错误的。用:
#define READ_TAMPER_PIN() ((FIO2PIN & PIN_TAMPER) >> 12)
回答by 0decimal0
According to c99 standard (§6.10.3 #10)
根据 c99 标准 (§6.10.3 #10)
A preprocessing directive of the form
形式的预处理指令
# define identifier lparen identifier-listopt ) replacement-list new-line
# 定义标识符 lparen identifier-listopt ) 替换列表换行
# define identifier lparen ... ) replacement-list new-line
# 定义标识符 lparen ... ) 替换列表换行
# define identifier lparen identifier-list , ... ) replacement-list new-line
# 定义标识符 lparen identifier-list , ... ) 替换列表换行
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 #definepreprocessing 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 listin 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.
定义一个带参数的类函数宏,在语法上类似于函数调用。参数由可选的标识符列表指定,其范围从它们在标识符列表中的声明扩展到终止#define预处理指令的换行符。类似函数的宏名称的每个后续实例后跟 a (作为下一个预处理标记引入了被定义中的替换列表替换的预处理标记序列(宏的调用)。被替换的预处理标记序列是由匹配终止)预处理标记,跳过中间匹配的左右括号预处理标记对。在组成类函数宏调用的预处理标记序列中,换行符被视为正常的空白字符。

