跟系统的数据模型有关。64位Windows使用LLP64数据模型,除了指针是64位,其他基本类型都没有变,long占据的是4个字节。而64位的类Unix平台均使用LP64数据模型,在该系统下,long占据8个字节。
可以查看一下MS的文档:
In 64-bitWindows, this assumption of parity in data type sizes is invalid. Making all data types 64 bits in length would waste space, because most applications do not need the increased size. However, applications do need pointers to 64-bit data, and they need the ability to have 64-bit data types in selected cases. These considerations led to the selection of an abstract data model called LLP64 (or P64). In the LLP64 data model, only pointers expand to 64 bits; all other basic data types (integer and long) remain 32 bits in length
链接如下:
https://docs.microsoft.com/zh-cn/windows/desktop/WinProg64/abstract-data-models