I have heard from books, presentation about minimal size for integral types in C/C++
Sizes below are in bytes:
sizeof(char) >= 1
sizeof(short) >= 2
sizeof(long) >= 4
sizeof(long long) >= 8
But I cannot find those guarantees in standards. So are there any guarantees required by compilers to implement defined in standards C++98 / C++2003 / C89 / C99?
Because there are none. Standard defines only some basic guarantees and requirements regarding values. You can find them in this document on page 33:
5.2.4.2.1 Sizes of integer types .
You can be sure, that:
sizeof(char) ≤ sizeof(short) ≤ sizeof(int) ≤ sizeof(long) ≤ sizeof(long long)
and
sizeof(float) ≤ sizeof(double) ≤ sizeof(long double)
Also:
sizeof(char)
is guaranteed to be 1sizeof(char) == sizeof(signed char) == sizeof(unsigned char)
Also, on most platforms:
sizeof(char) = 1
sizeof(short) = 2
sizeof(int) = 4
sizeof(long) = 4
sizeof(long long) = 8
(1)
(1) long long
is not a standard type. GCC and VC++ have supported it for a long time now, but official support came with C++ 11:
long long
- target type will have width of at least 64 bits. (since C++11)
Note, that even if sizeof(char)
is guaranteed to be 1
, it doesn't mean, that char
is 8 bit long. CHAR_BIT
defines number of bits in char
type. These days, almost all architectures use 8 bits per byte, but some older architectures used to have 7.