sizeof(int) <= sizeof(long) <= sizeof(long long) 总是正确的?

问题描述:

从 C 标准来看,int 至少为 16 位,long 至少为 32 位,long long 至少为 64 位(如果有的话)(某些平台可能不支持).只是想知道作为标题的句子是否总是正确的.

From C standard, int has of at least 16bit, long has of at least 32bit and at least 64bit for long long if any (some platforms may not support). Just wondering if the sentence as title is always true.

没有.该标准仅定义了每种类型的最小范围.可以想象,int 可以有 16 位范围,但填充 48 位,使其成为 64 位(8 字节,如果 CHAR_BITS == 8),而 long 是 32 位(4 字节).

No. The standard only defines the minimum ranges for each of those types. Conceivably int could have a 16-bit range, but 48 bits of padding, bringing it to 64-bits (8 bytes, if CHAR_BITS == 8), while long is 32-bits (4 bytes).

当然,这很愚蠢.但这并不是被禁止的.

Of course, this would be silly. But it's not forbidden, as such.

但是请注意,sizeof(char) == 1,根据定义.所以 sizeof(char) <= sizeof(anything else).

Note, however, that sizeof(char) == 1, by definition. So sizeof(char) <= sizeof(anything else).