由唯一的类型限定符组成的声明说明符
Declaration specifier which consists of the only type-qualifier
定义明确,long
、signed long
、long int
、signed long int
都指定了相同的类型。实际上, N2310/6.7.2(p5)
:
Each of the comma-separated multisets designates the same type, except
that for bit-fields, it is implementation-defined whether the
specifier int designates the same type as signed int
or the same type
as unsigned int
.
据我所知,int
可以简单地省略。现在考虑声明:
const a;
GCC
警告
warning: type defaults to ‘int’ in declaration of ‘a’
这样的声明是语法允许的,因为这里的 declarator
是一个标识符 a
,declaration-specifiers
是一个类型限定符 const
。 N2310/6.7(p1)
:
declaration:
declaration-specifiers init-declarator-list opt ;
[...]
declaration-specifiers:
[...]
type-qualifier declaration-specifiers opt
[...]
但是通过标准部分 6.7
和 6.7.3
(甚至没有这样的例子)我无法证明这样的声明实际上隐式声明了 a
的类型const int
.
根据标准,声明 const a;
中应该包含什么类型 a
?
6.7.2p2:
At least one type specifier shall be given in the declaration specifiers in each declaration, and in the specifier-qualifier list in each struct declaration and type name.
const a;
无效。
C89/C90 在这些情况下通常默认为 int
,这就是编译器仍然支持它的原因,但 "implicit int" 在 C99 中被正式删除。
ISO 9899:1990 在 6.5.2 类型说明符 下有以下条目:
int
, signed
, signed int
, or no type specifiers
定义明确,long
、signed long
、long int
、signed long int
都指定了相同的类型。实际上, N2310/6.7.2(p5)
:
Each of the comma-separated multisets designates the same type, except that for bit-fields, it is implementation-defined whether the specifier int designates the same type as
signed int
or the same type asunsigned int
.
据我所知,int
可以简单地省略。现在考虑声明:
const a;
GCC
警告
warning: type defaults to ‘int’ in declaration of ‘a’
这样的声明是语法允许的,因为这里的 declarator
是一个标识符 a
,declaration-specifiers
是一个类型限定符 const
。 N2310/6.7(p1)
:
declaration:
declaration-specifiers init-declarator-list opt ;
[...]
declaration-specifiers:
[...]
type-qualifier declaration-specifiers opt
[...]
但是通过标准部分 6.7
和 6.7.3
(甚至没有这样的例子)我无法证明这样的声明实际上隐式声明了 a
的类型const int
.
根据标准,声明 const a;
中应该包含什么类型 a
?
6.7.2p2:
At least one type specifier shall be given in the declaration specifiers in each declaration, and in the specifier-qualifier list in each struct declaration and type name.
const a;
无效。
C89/C90 在这些情况下通常默认为 int
,这就是编译器仍然支持它的原因,但 "implicit int" 在 C99 中被正式删除。
ISO 9899:1990 在 6.5.2 类型说明符 下有以下条目:
int
,signed
,signed int
, or no type specifiers