long 保證至少為 32 位元嗎?
C 標準規定了整數資料儲存方面的以下優先順序基本類型:
sizeof(char) ≤ sizeof(short int) ≤ sizeof(int) ≤ sizeof(long int)
第1.7/1 節中提供了有關char 大小的進一步說明:
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.
這表示sizeof(char) 可以是1 到n 之間的任何值位,其中n 取決於實作。然而,C 標準也需要了解C 標準(1.2/1),它定義了long 可以容納的值的最小限制:
LONG_MIN = -2147483647 // -(2^31 - 1) LONG_MAX = +2147483647 // 2^31 - 1
因為long 必須能夠同時容納正數和負數如果值達到這些限制,則從邏輯上推斷出long 的大小必須至少為32 位元。
簡而言之,雖然 C 標準未指定位元組中的位數,但對 LONG_MIN 施加的最小限制LONG_MAX 意味著 long 必須至少有 32 位元儲存空間。
以上是C 中的「長」保證至少為 32 位元嗎?的詳細內容。更多資訊請關注PHP中文網其他相關文章!