栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C: 编译错误:expected identifier or ‘(’ before numeric constant

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C: 编译错误:expected identifier or ‘(’ before numeric constant

文章目录
  • 错误
  • 原因

错误

字面意思,期望一个变量名(标识符),或者在数字常量前面期望一个左括号。

macro.c: In function ‘main’:
macro.c:9:6: error: expected identifier or ‘(’ before numeric constant
  int PIPE_BUF = 0;
      ^~~~~~~~
原因

在include linux/limits.h 之后,定义了一个PIPE_BUF 变量。但是在 limit.h 头文件里已经有一个PIPE_BUF定义,这个变量在预编译阶段,就会被替换成这个宏定义。出现下面的情况。

#include 
#define STR(x) #x
#define XSTR(x) STR(x)
int main (void)
{
 int PIPE_BUF = 0;
 assert (strcmp ("PIPE_BUF", XSTR (PIPE_BUF)) == 0);
 return 0;
}

==== 预编译结果
# 7 "macro.c"
int main (void)
{
 int
# 9 "macro.c" 3 4
    4096    、、、、 这里搞了替换,就能明白为什么期望一个括号了,因为这个替换之后是个数字常量。
# 9 "macro.c"  
             = 0;

# 10 "macro.c" 3 4
((void) sizeof ((
# 10 "macro.c"
strcmp ("PIPE_BUF", "4096") == 0
# 10 "macro.c" 3 4
) ? 1 : 0), __extension__ ({ if (
# 10 "macro.c"
strcmp ("PIPE_BUF", "4096") == 0
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/657518.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号