898

long 在不同操作系统下所占用的字节数

不同平台下C\C++数值数据类型长度如下:

类型 win32 win64 linux32 linux64

其中long类型和指针类型需要特别注意,编写跨平台的软件时尽量不要使用long类型,或者需要对long类型做特殊处理---------------------

由上图可以说明, long在linux下64位与win64位下表现不一致。这可能会导致一些精度问题,需注意。推荐使用std一套有关整形的申明, 详细请参阅stdint.h

typedef signed char int8_t;typedef short int16_t;typedef int int32_t;typedef long long int64_t;typedef unsigned char uint8_t;typedef unsigned short uint16_t;typedef unsigned int uint32_t;typedef unsigned long long uint64_t;---------------------