Hacker News new | ask | show | jobs
by detaro 1176 days ago
> I thought char was required by the C standard to be 8 bits

It's not. (EDIT: it is required to be at least 8 bits though)

2 comments

Welcome to C! The guns are free, but you can only point them at your foot.

The C standard specifies so much less than everyone thinks.

It specifies so much less, precisely to allow it to be usable on such weird architectures.
I wouldn't really qualify this as a foot gun, but rather appropriate flexibility. 98% of people never encounter it, and the 2% that do are happy that it is that way, and I don't think alternative approaches like having the compiler hide it are appropriate for C.
I thought char was required by the C standard to be 8 bits

Common misconception.

to be at least 8 bits though

At least 8 bits for the latter-day compilers for which the 'standard' was the guide. I have seen C compilers where char was 6-bit or 7-bits matching the underlying hardware. However, those probably never implemented more than K&R or some pre-standardization perversion of it.

Also...as noted a char can be more than 8 bits, pre- and post-standardization. I've heard tell of (at least) 9-, 16-, 24- and 32-bit chars on more or less weird platforms.

At some point I'm sure the standards bodies will do some variation of depreciating 8-ish-bit char's for 32-bit Unicode as the standard representation for text.