What platforms have something other than 8-bit char?

char is also 16 bit on the Texas Instruments C54x DSPs, which turned up for example in OMAP2. There are other DSPs out there with 16 and 32 bit char. I think I even heard about a 24-bit DSP, but I can’t remember what, so maybe I imagined it.

Another consideration is that POSIX mandates CHAR_BIT == 8. So if you’re using POSIX you can assume it. If someone later needs to port your code to a near-implementation of POSIX, that just so happens to have the functions you use but a different size char, that’s their bad luck.

In general, though, I think it’s almost always easier to work around the issue than to think about it. Just type CHAR_BIT. If you want an exact 8 bit type, use int8_t. Your code will noisily fail to compile on implementations which don’t provide one, instead of silently using a size you didn’t expect. At the very least, if I hit a case where I had a good reason to assume it, then I’d assert it.

Leave a Comment