Are there machines, where sizeof(char) != 1, or at least CHAR_BIT > 8?

后端 未结 3 1931
梦毁少年i
梦毁少年i 2020-11-22 02:33

Are there machines (or compilers), where sizeof(char) != 1?

Does C99 standard says that sizeof(char) on standard complianc

3条回答
  •  长发绾君心
    2020-11-22 03:28

    There are no machines where sizeof(char) is 4. It's always 1 byte. That byte might contain 32 bits, but as far as the C compiler is concerned, it's one byte. For more details, I'm actually going to point you at the C++ FAQ 26.6. That link covers it pretty well and I'm fairly certain C++ got all of those rules from C. You can also look at comp.lang.c FAQ 8.10 for characters larger than 8 bits.

    Upd2: But sizeof result is NOT a BYTES ! it is the size of CHAR. And char can be 2 byte, or (may be) 7 bit?

    Yes, it is bytes. Let me say it again. sizeof(char) is 1 byte according to the C compiler. What people colloquially call a byte (8 bits) is not necessarily the same as what the C compiler calls a byte. The number of bits in a C byte varies depending on your machine architecture. It's also guaranteed to be at least 8.

提交回复
热议问题