The reason why this has been done in the past is portability. C and C++ do not make specific guarantees of the size of int
, long
and short
, while library designers often require it.
A common solution is to define their own aliases for data types, and changing the definitions based on the specific platform, making sure that the type of the appropriate size gets used.
This problem originated in C, and has been addressed by introduction of stdint.h
header file (renamed to cstdint
in C++). Including this header lets you declare types int32_t
, int16_t
, etc. However, libraries developed prior to introduction of stdint.h
and libraries that are required to compile on platforms lacking this header are using the old workaround.