C语言 gcc c 错误:在数字常量之前预期为 ')'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18383394/
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
gcc c error: expected ')' before numeric constant
提问by ElvishPriestley
Hi I have been trying to port LWIP to a new arm device. When compiling the code i get the error message:
嗨,我一直在尝试将 LWIP 移植到新的 arm 设备。编译代码时,我收到错误消息:
"lwip/lwip-1.4.0/src/include/lwip/memp_std.h:35:23: error: expected ')' before numeric constant"
When I go to this file this and below this several similar macros is what I find on that line:
当我转到这个文件时,我在该行中找到了以下几个类似的宏:
LWIP_MEMPOOL(RAW_PCB, MEMP_NUM_RAW_PCB, sizeof(struct raw_pcb), "RAW_PCB")
If I remove the need for this macro with a define to deactivate the RAW functionality the error moves to the next LWIP_MEMPOL() macro.
如果我通过定义取消激活 RAW 功能来消除此宏的需要,则错误将移至下一个 LWIP_MEMPOL() 宏。
The define it seems to want to put a ')' in front of is defined as this:
它似乎想在前面放一个 ')' 的定义被定义为:
#define MEMP_NUM_RAW_PCB 1
The RAW_PCB is not defined but is "combined with MEMP_" to create an element in an enum.
RAW_PCB 未定义,但“与 MEMP_ 结合”以在枚举中创建元素。
I have tried to complie the whole ting with the -E option to get human redable object files and see if i can find any open '(' around the areas where MEMP_RAW_PCB apears and the substitution of MEMP_NUM_RAW_PCB to 1 but I have not found any by manual inspection yet.
我试图用 -E 选项来编译整个 ting 以获得人类可编辑的对象文件,看看我是否能在 MEMP_RAW_PCB 出现的区域周围找到任何打开的 '(' 并将 MEMP_NUM_RAW_PCB 替换为 1 但我没有找到任何人工检查。
Are there any suggestions on what can be going on here or what more I can do or look for to find the cause of the error?
关于这里可能发生的事情或我还能做什么或寻找什么来找到错误的原因,有什么建议吗?
I should maybe add that so far I don't call on any of the LWIP code from main() or any of the functions used in main().
我应该补充一点,到目前为止我没有调用 main() 中的任何 LWIP 代码或 main() 中使用的任何函数。
采纳答案by wii
I solved it with:
我用以下方法解决了它:
#ifndef MEMP_STD_H_
#define MEMP_STD_H_
... // memp_std.h codes ...
#endif //#ifndef MEMP_STD_H_
回答by Luv2code
If you're defining it with the dash-D option, it will generate the 1 by default, e.g.:
如果您使用 dash-D 选项定义它,它会默认生成 1,例如:
gcc -D 'MAX(A,B) ((A) < (B)? (B) : (A))' ...
Generates:
产生:
#define MAX(A,B) ((A) < (B)? (B) : (A)) 1
And you get the error: expected ‘)' before numeric constantmessage at the line where the substitution occurs because of that trailing 1, e.g.:
error: expected ‘)' before numeric constant由于尾随 1,您会在发生替换的行处收到消息,例如:
int maxval = MAX(i,j);
// generates: int maxval = ((i) < (j)? (j) : (i)) 1;
Conversely, if you use the assignment operatorto explicitly define the value, it will generate it the way you expected. E.g.:
相反,如果您使用赋值运算符显式定义值,它将以您期望的方式生成它。例如:
int maxval = MAX(i,j);
// generates: int maxval = ((i) < (j)? (j) : (i));
回答by jxh
The error suggests you have unbalanced parentheses. The code you have provided thus far does not indicate where this problem is, but since )is expected, it probably means the error is actually in the lines of code preceding the one you have shown.
该错误表明您的括号不平衡。到目前为止,您提供的代码并未指出此问题的出处,但由于)是预期的,这可能意味着错误实际上出在您所显示的代码行之前的代码行中。
Examine the code preceding the line you have shown (perhaps after using gcc -E) to check to see if all the parentheses are balanced.
检查您显示的行之前的代码(可能在使用之后gcc -E)以检查所有括号是否平衡。

