在所有版本的C和C ++中,有签名,无符号,长整型和短整型的所有有效类型? [英] Are signed, unsigned, long and short all valid types in all versions of C and C++?

查看:163
本文介绍了在所有版本的C和C ++中,有签名,无符号,长整型和短整型的所有有效类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在N3797 7.1.1 / 3中有以下注释:



注意:由于默认情况下是signed,unsigned,long和short隐含int,一个类型名称出现在这些说明符之一后面被视为(重新)声明的名称。



一张纸条。在标准中有一个地方使规范性声明具有相同的效果吗?



是符合标准的C和C ++使用签名无符号不包含 int



或者,为了将它放在代码中,符合以下标准,如果是这样,它在哪里说?

 签署a;无符号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);

[我不知道是否推荐或首选,因为害怕得到基于意见的答案。

解决方案

我知道这一直是这样,但我们至少可以回到最早公开的草案标准。对于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.

这篇关于在所有版本的C和C ++中,有签名,无符号,长整型和短整型的所有有效类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆