使用 gcc
时,代码应为:
register a = 3;
static b = 3;
使用-std=c89 -pedantic-errors
标记是允许的,尽管会有一个警告。
但是在使用-std=c99 -pedantic-errors
标记时会收到错误信息。
我想知道C89标准中的哪个部分允许“隐式int”规则?
使用 gcc
时,代码应为:
register a = 3;
static b = 3;
使用-std=c89 -pedantic-errors
标记是允许的,尽管会有一个警告。
但是在使用-std=c99 -pedantic-errors
标记时会收到错误信息。
我想知道C89标准中的哪个部分允许“隐式int”规则?
在 C89 中允许隐式 int 规则的章节是第 3.5.2
节 Type specifiers,其中写道(强调是我的):
int、signed、signed int 或没有类型描述符
评论区的 Keith Thompson 指出,在 C90 中,该章节是 6.5.2
,并且说:“唯一的区别是 ISO 要求的一些介绍性材料,导致章节重新编号。”
在 C99 中发生了更改,该章节是 6.7.2
Type specifiers,它说:
int、signed 或 signed int
这也在文档N661:Disallow implicit "int" in declarations中讨论:
在 6.5.2 类型说明符中进行更改;在约束条件的第一个段落的开头添加新句子: 在声明中,声明说明符中必须至少给定一个类型说明符。
Change in 6.5.2 Type specifiers, Constraints, from: -- int, signed, signed int, or no type specifiers to: -- int, signed, or signed int