64位上的类型长度怎么这么乱

来源:百度知道 编辑:UC知道 时间:2024/06/15 14:37:08
sizeof( int ), sizeof( long ), sizeof( void* )
在vs2005 16们编译环境下分别是 2, 4, 2
在vs2005 32位编译环境下分别是 4, 4, 4
在vs2005 64们编译环境下分别是 4, 4, 8
在gcc 64们编译环境下分别是 4, 8, 4

为什么这么乱
to: BlueWanderer
16位我说错了,不是vs2005的,是tubro c的
vs2005 64们环境下是 4,4,8 我验证过的

to: Tian-C
gcc64位环境我就是编译的c程序,不是c++程序,得出的是 sizeof(int)==4

to: fuchuangbob
gcc64位环境,sizeof(long) == 8

16位下int型2字节,long型4字节
32位下,int与long同为4字节
64位下,int 4,long 8
而指针类型,只与CPU地址总线位数有关,即通常所说的多少位CPU。
=============================================================
就这么样的标准,记住就OK了

其实C语言标准int 是2个字节的,而C++就是4个字节的,这个跟编译环境无关~~,由于VS2005用的是C++编译器,所以按照C++标准int 就成了4个字节。
指针类型的长度是和计算机的字长有关的。。所以在不同环境下他是不同的~~这也说明CPU的寻址能力不同
-------------------------------
...原来C语言的int型也是随着机器的字长改变的,更不同的编译器有关。。小弟才疏学浅帮不了
C Language Reference
The size of a signed or unsigned int item is the standard size of an integer on a particular machine. For example, in 16-bit operating systems, the int type is usually 16 bits, or 2 bytes. In 32-bit operating systems, the int type is usually 32 bits, or 4 bytes. Thus, the int type is equivalent to either the short int or the long int type, and the unsigned int type is equivalent to either the unsigned short or the unsigned long type, depending on the target environment. The int types all represent signed values unless specified othe