Size of 'long integer' data type (C++) on various architectures and OS

The size of a "long" integer varies between architectures and operating systems.

The Intel® Compiler is compatible and inter-operable with Microsoft* Visual C++ on Windows* and with gcc* on Linux* and Mac OS X*. Consequently, the sizes of fundamental types are the same as for these compilers. The size of a “long” integer in particular depends on the operating system and the targeted architecture as follows:

OSArchitectureSize of "long" type
WindowsIA-324 bytes
 Intel® 644 bytes
LinuxIA-32 4 bytes
 Intel® 648 bytes
mac OSIntel® 648 bytes

  

Consequently, when programs which use "long" integer data type are ported from IA-32 Linux to Intel® 64 Linux, or from Intel® 64 Windows to Intel® 64 Linux, the behavior might change. (Note that the size of pointers is expected to change between IA-32 and Intel® 64).

In addition, the size of a "long double" also varies by operating system.

On Windows*, the size is 8 bytes by default. On Linux or Mac OS X, 10 bytes are used for the representation of a long double, although the allocated size may be larger (12 bytes on IA-32 Linux; 16 bytes elsewhere).

Suggestion:   If it is important to you for integer types to have the same size on all Intel platforms, then consider replacing "long" by either "int" or "long long". The size of the "int" integer type is 4 bytes and the size of the "long long" integer type is 8 bytes for all the above combinations of operating system and architecture.

On Windows, the representation of "long double" may be increased to 10 bytes by use of the command line switch /Qlong-double. The corresponding memory allocation is 16 bytes.
For more complete information about compiler optimizations, see our Optimization Notice.