4 ms·
sizeof(long) >= 4 sizeof(int) >= 2 sizeof(long) >= sizeof(int) That's all you can expect.
by marcosdumay 10y ago
sizeof(long) >= 4
sizeof(int) >= 2
sizeof(long) >= sizeof(int)
That's all you can expect.
- klodolph 10y agoYou literally cannot expect the first two. On word-addressable hardware, you could easily get sizeof(long) = sizeof(int) = 1. This happens on DSPs.
- deleted 10y ago[deleted]
- deleted 10y ago[deleted]
- marcosdumay 10y agoYes. Didn't think about machines where the memory isn't composed of bytes. The best approach is still to not expect anything.
- vortico 10y agoI understand some implementations might break this rule, but what standard states this?
- jcranmer 10y ago(Derived from C11, specifically N1570). §5.2.4.2.1 CHAR_BIT is at least 8 USHRT_MAX is at least 2^16 - 1 UINT_MAX is at least 2^16 - 1 ULONG_MAX is at least 2^32 - 1 ULLONG_MAX is at least 2^64 - 1 §6.2.5p8 guarantees that integers of increasing conversion ranks obeys subset relations, and §6.3.1.1 lays out that short, int, and long have conversion ranks in that order. Thus, sizeof(char) = 1 ≤ sizeof(short) ≤ sizeof(int) ≤ sizeof(long) ≤ sizeof(long long).
- loeg 10y agoAll of these were present in C99 as well.
- deleted 10y ago[deleted]
- loeg 10y agoAlso long long >= 8, per C99.
- bonzini 10y agoAssuming CHAR_BIT is 8, of course.