更新时间:2022-10-26 18:53:02
我知道这一直是这样,但我们至少可以回到最早公开的草案标准。对于C ++,将 1804 和 7.1.5.2
简单类型说明符 表7
包含以下条目:
无符号的unsigned int
signedint
longlong int
shortshort int
我们可以返回 C99 部分 6.7.2
类型说明说: ...]
类型说明符的每个列表应该是以下集合之一(当
多于一行时,以逗号分隔); [...]
并包括以下项目符号:
- short,signed short,short int或signed short int
- int,signed或signed int
- unsigned或unsigned int
- long,signed long,long int或signed long int
因此,所有所有符合标准的类型说明符和两个引号都来自相应标准草案的规范部分。
In N3797 7.1.1/3 there is the following note:
Note: Since signed, unsigned, long, and short by default imply int, a type-name appearing after one of those specifiers is treated as the name being (re)declared.
But this is only a note. Is there somewhere in the standard that makes a normative statement to the same effect?
Is is proper standards-compliant C and C++ to use signed, unsigned, long and short without int in each and every situation?
Or, to put it in code, are the following standards-compliant and if so where does it say so?
signed a;
unsigned b;
short c;
long d;
signed f(signed p, unsigned q, short r, long s);
unsigned* f(signed* p, unsigned* q, short* r, long* s);
[I hesitate to ask whether it's recommended or preferred, for fear of getting opinion-based answers.]
As far I know it has always been that way but we can at least go back to the earliest publicly available draft standards. For C++ would be 1804 and in section 7.1.5.2
Simple type specifiers Table 7
simple-type-specifiers and the types they specify includes the following entries:
unsigned "unsigned int"
signed "int"
long "long int"
short "short int"
for C we can go back to C99 which in section 6.7.2
Type specifiers says:
[...]Each list of type specifiers shall be one of the following sets (delimited by commas, when there is more than one set on a line); [...]
and includes the following bullets:
— short, signed short, short int, or signed short int
— int, signed, or signed int
— unsigned, or unsigned int
— long, signed long, long int, or signed long int
So these all all standards compliant type specifiers and both quotes come from the normative section of the respective draft standards.