4 ms·
The only guarantee that C gives you is that sizeof char == 1, and even that's not as useful as it looks.
by mark-r 5y ago
The only guarantee that C gives you is that sizeof char == 1, and even that's not as useful as it looks.
- SAI_Peregrinus 5y agoIt also guarantees that char is at least 8 bits.
- account42 5y agoAnd POSIX does guarantees that CHAR_BIT == 8 so in practice this is only a concern on embedded platform where you are only dealing with "C-ish" anyway.
- SAI_Peregrinus 5y agoOr any other non-POSIX system. I'm not sure what Windows guarantees, but it's definitely not a POSIX system.
- account42 5y agoHow many non-embedded non-POSIX systems do you know? Windows also guarantees CHAR_BIT == 8 and since most software is first written for Windows or POSIX there is plenty of software that assumes that CHAR_BIT == 8. That means that anything that will want to run general software needs to also ensure CHAR_BIT == 8 - not to mention all the algorithms and data formats designed around you being able to efficiently access octets. The only platforms that can get away with CHAR_BIT != 8 are precisely those that have software specially written for them, i.e. embedded systems.