In today's cross-platform C++ (or C) world we have:
Data model | short | int | long | long long | pointers/size_t | Sample operating systems
...
LLP64/IL32P64 16 32 32 64 64 Microsoft Windows (x86-64 and IA-64)
LP64/I32LP64 16 32 64 64 64 Most Unix and Unix-like systems, e.g. Solaris, Linux, BSD, and OS X; z/OS
...
What this means today, is that for any "common" (signed) integer, int
will suffice and can possibly still be used as the default integer type when writing C++ application code. It will also - for current practical purposes - have a consistent size across platforms.
Iff a use case requires at least 64 bits, we can today use long long
, though possibly using one of the bitness-specifying types or the __int64
type might make more sense.
This leaves long
in the middle, and we're considering outright banning the use of long
from our application code.
Would this make sense, or is there a case for using long
in modern C++ (or C) code that has to run cross platform? (platform being desktop, mobile devices, but not things like microcontrollers, DSPs etc.)
Possibly interesting background links:
- What does the C++ standard state the size of int, long type to be?
- Why did the Win64 team choose the LLP64 model?Why did the Win64 team choose the LLP64 model?
- 64-Bit Programming Models: Why LP64? (somewhat aged)
- Is
long
guaranteed to be at least 32 bits? (This addresses the comment discussion below. Answer.)