What is the bit size of long on 64-bit Windows? What is the bit size of long on 64-bit Windows? c c

What is the bit size of long on 64-bit Windows?


In the Unix world, there were a few possible arrangements for the sizes of integers and pointers for 64-bit platforms. The two mostly widely used were ILP64 (actually, only a very few examples of this; Cray was one such) and LP64 (for almost everything else). The acronynms come from 'int, long, pointers are 64-bit' and 'long, pointers are 64-bit'.

Type           ILP64   LP64   LLP64char              8      8       8short            16     16      16int              64     32      32long             64     64      32long long        64     64      64pointer          64     64      64

The ILP64 system was abandoned in favour of LP64 (that is, almost all later entrants used LP64, based on the recommendations of the Aspen group; only systems with a long heritage of 64-bit operation use a different scheme). All modern 64-bit Unix systems use LP64. MacOS X and Linux are both modern 64-bit systems.

Microsoft uses a different scheme for transitioning to 64-bit: LLP64 ('long long, pointers are 64-bit'). This has the merit of meaning that 32-bit software can be recompiled without change. It has the demerit of being different from what everyone else does, and also requires code to be revised to exploit 64-bit capacities. There always was revision necessary; it was just a different set of revisions from the ones needed on Unix platforms.

If you design your software around platform-neutral integer type names, probably using the C99 <inttypes.h> header, which, when the types are available on the platform, provides, in signed (listed) and unsigned (not listed; prefix with 'u'):

  • int8_t - 8-bit integers
  • int16_t - 16-bit integers
  • int32_t - 32-bit integers
  • int64_t - 64-bit integers
  • uintptr_t - unsigned integers big enough to hold pointers
  • intmax_t - biggest size of integer on the platform (might be larger than int64_t)

You can then code your application using these types where it matters, and being very careful with system types (which might be different). There is an intptr_t type - a signed integer type for holding pointers; you should plan on not using it, or only using it as the result of a subtraction of two uintptr_t values (ptrdiff_t).

But, as the question points out (in disbelief), there are different systems for the sizes of the integer data types on 64-bit machines. Get used to it; the world isn't going to change.


It is not clear if the question is about the Microsoft C++ compiler or the Windows API. However, there is no [c++] tag so I assume it is about the Windows API. Some of the answers have suffered from link rot so I am providing yet another link that can rot.


For information about Windows API types like INT, LONG etc. there is a page on MSDN:

Windows Data Types

The information is also available in various Windows header files like WinDef.h. I have listed a few relevant types here:

Type                        | S/U | x86    | x64----------------------------+-----+--------+-------BYTE, BOOLEAN               | U   | 8 bit  | 8 bit----------------------------+-----+--------+-------SHORT                       | S   | 16 bit | 16 bitUSHORT, WORD                | U   | 16 bit | 16 bit----------------------------+-----+--------+-------INT, LONG                   | S   | 32 bit | 32 bitUINT, ULONG, DWORD          | U   | 32 bit | 32 bit----------------------------+-----+--------+-------INT_PTR, LONG_PTR, LPARAM   | S   | 32 bit | 64 bitUINT_PTR, ULONG_PTR, WPARAM | U   | 32 bit | 64 bit----------------------------+-----+--------+-------LONGLONG                    | S   | 64 bit | 64 bitULONGLONG, QWORD            | U   | 64 bit | 64 bit

The column "S/U" denotes signed/unsigned.


This article on MSDN references a number of type aliases (available on Windows) that are a bit more explicit with respect to their width:

http://msdn.microsoft.com/en-us/library/aa505945.aspx

For instance, although you can use ULONGLONG to reference a 64-bit unsigned integral value, you can also use UINT64. (The same goes for ULONG and UINT32.) Perhaps these will be a bit clearer?