C/C++ 中整数类型别名的标准保证?例如:是“无符号"吗?总是等于“unsigned int"? [英] Standard guarantees for aliases of integer types in C/C++? E.g.: Is "unsigned" always equal to "unsigned int"?

查看:39
本文介绍了C/C++ 中整数类型别名的标准保证?例如:是“无符号"吗?总是等于“unsigned int"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一个问题:

  • unsigned"总是与unsigned int"一样吗?
  • signed"总是和int"一样吗?
  • short"总是与signed short"一样吗?
  • 是……

第二个问题:

如果 C/C++ 标准规定了上述问题的答案,哪些段落与它们相关?

If a C/C++ standard specifies answers to above questions, what paragraphs are related to them?

推荐答案

是的,这些都是有保证的.在 C++11 中,请参阅 §7.1.6.2[dcl.type.simple]/table 10,其中列出了所有简单类型说明符(及其组合)及其含义.例如,该表包括以下内容:

Yes, these are guaranteed. In C++11, see §7.1.6.2[dcl.type.simple]/table 10, which lists all of the simple type specifiers (and combinations thereof) and what they mean. For example, the table includes the following:

unsigned      => unsigned int
unsigned int  => unsigned int

signed        => int
signed int    => int
int           => int

C11 在 §6.7.2/2 中有一个类似的映射(它的格式不同,但它指定了相同的等效组合组,至少对于 C 和 C++ 共有的所有类型).

C11 has a similar mapping in §6.7.2/2 (it's formatted differently, but otherwise it specifies the same groups of equivalent combinations, at least for all of the types common to C and C++).

这篇关于C/C++ 中整数类型别名的标准保证?例如:是“无符号"吗?总是等于“unsigned int"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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