C89标准中的哪个章节允许"implicit int"规则?

14

使用 gcc 时,代码应为:

register a = 3;
static b = 3;

使用-std=c89 -pedantic-errors 标记是允许的,尽管会有一个警告。

但是在使用-std=c99 -pedantic-errors标记时会收到错误信息。

我想知道C89标准中的哪个部分允许“隐式int”规则?

1个回答

16

在 C89 中允许隐式 int 规则的章节是第 3.5.2Type 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

5
1989 年的 ANSI C 标准中的 3.5.2 节在 1990 年的 ISO C 标准中被重新编号为 6.5.2 节。(这两个标准描述完全相同的语言。唯一的区别是 ISO 需要一些介绍性材料,导致章节重新编号。) - Keith Thompson

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接