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

时间:2023-01-09 23:24:31

int 和 long 在windows和linux 下所占字节数如下图所示

  win32 win64 linux32 linux64
int  4 4 4 4
long 4 4 4 8
由上图可以说明, 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;