Metasize
C++ defines signed and unsigned variants of the types
char,
short,
int,
long,
but does not define their sizes.
Occasionally, knowing their sizes is useful
-- or, more often, knowing which of them is a particular size is useful.
Here are three portable examples of how to use C and C++ type information to determine 8-, 16-, 32-, and 64-bit signed and unsigned types, if they exist. They rely upon the following guarantees of ISO C++:
sizeof(char) <=
sizeof(short) <=
sizeof(int) <=
sizeof(long)
SCHAR_MAX >= 127 (2^7 - 1)SHRT_MAX >= 32767 (2^15 - 1)INT_MAX >= 32767 (2^15 - 1)LONG_MAX >= 2147483647 (2^31 - 1)