Is long Guaranteed to be at Least 32 Bits?
The C Standard dictates the following order of precedence in terms of data storage for integral fundamental types:
sizeof(char) ≤ sizeof(short int) ≤ sizeof(int) ≤ sizeof(long int)
Further clarification on the size of char is provided in section 1.7/1:
The fundamental storage unit in the C++ memory model is the byte. A byte is at least large enough to contain any member of the implementation’s basic character set and is composed of a contiguous sequence of bits, the number of which is implementation-defined.
This suggests that sizeof(char) can be anywhere from 1 to n bits, where n is implementation-dependent. However, the C Standard also requires knowledge of the C Standard (1.2/1), which defines minimum limits for the values that long can accommodate:
LONG_MIN = -2147483647 // -(2^31 - 1) LONG_MAX = +2147483647 // 2^31 - 1
Since long must be able to hold both positive and negative values up to these limits, it is logically deduced that long must be at least 32 bits in size.
In short, while the C Standard leaves the number of bits in a byte unspecified, the minimum limits imposed on LONG_MIN and LONG_MAX imply that long must have at least 32 bits of storage.
The above is the detailed content of Is `long` Guaranteed to be at Least 32 Bits in C ?. For more information, please follow other related articles on the PHP Chinese website!