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

ID 660203
Updated 12/26/2018
Version Latest
Public

author-image

By

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:

OS Architecture Size of "long" type
Windows IA-32 4 bytes
  Intel® 64 4 bytes
Linux IA-32  4 bytes
  Intel® 64 8 bytes
mac OS Intel® 64 8 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.