size guarantee for integral/arithmetic types in C and C++

前端 未结 7 2145
难免孤独
难免孤独 2020-12-15 00:49

I know that the C++ standard explicitly guarantees the size of only char, signed char and unsigned char. Also it gives guarantees that

7条回答
  •  萌比男神i
    2020-12-15 00:56

    18.2.2 guarantees that has the same contents as the C library header .

    The ISO C90 standard is tricky to get hold of, which is a shame considering that C++ relies on it, but the section "Numerical limits" (numbered 2.2.4.2 in a random draft I tracked down on one occasion and have lying around) gives minimum values for the INT_MAX etc. constants in . For example ULONG_MAX must be at least 4294967295, from which we deduce that the width of long is at least 32 bits.

    There are similar restrictions in the C99 standard, but of course those aren't the ones referenced by C++03.

    This does not guarantee that long is at least 4 bytes, since in C and C++ "byte" is basically defined to mean "char", and it is not guaranteed that CHAR_BIT is 8 in C or C++. CHAR_BIT == 8 is guaranteed by both POSIX and Windows.

提交回复
热议问题