我正在寻找有关基本C++类型大小的详细信息.我知道这取决于架构(16位,32位,64位)和编译器.
但是有没有C++的标准?
我在32位架构上使用Visual Studio 2008.这是我得到的:
char : 1 byte
short : 2 bytes
int : 4 bytes
long : 4 bytes
float : 4 bytes
double: 8 bytes
Run Code Online (Sandbox Code Playgroud)
我试图找到,但没有成功,可靠的信息,表述的大小char,short,int,long,double,float(和其他类型的我没想到的),在不同的体系结构和编译器.
我正在使用一64-bit台机器.
$ uname -m
x86_64
$ file /usr/bin/file
/usr/bin/file: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, stripped
$
Run Code Online (Sandbox Code Playgroud)
当我运行以下程序时,我得到了sizeof(int)as 4-bytes.
#include <stdio.h>
int main(void)
{
printf("sizeof(int) = %d bytes\n", (int) sizeof(int));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如果我运行一个16-,32-和64-位机,那么不就意味着一个大小integer为16-,32-并64-分别位?
在我的机器上,我找到了WORD_BITIS 32.它不应该64在64-bit机器上吗?
$ getconf WORD_BIT
32 …Run Code Online (Sandbox Code Playgroud) C++ standard says only that int has to be at least 16 bits wide. And at least according to cppreference, it's almost always either 16 or 32 bits wide:
Run Code Online (Sandbox Code Playgroud)data model int width in bits ---------------------------------- C++ standard at least 16 LP32 16 ILP32 32 LLP64 32 LP64 32...
Other models are very rare. For example, ILP64 (8/8/8: int, long, and pointer are 64-bit) only appeared in some early 64-bit Unix systems (e.g. Unicos on Cray).
Is …
如果您需要一个计数变量,肯定必须有一个整数必须支持的上限和下限.那么为什么不通过选择适当的(u)int_fastxx_t数据类型来指定这些限制呢?