Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is CHAR_BIT ever > 8?

Tags:

c

char

byte

bit

The ISO C Standard requires CHAR_BIT to be at least 8.

With POSIX mandating CHAR_BIT be equal to 8, and (almost?) all networking and communication standards using octets, is there any contemporary C implementation where CHAR_BIT > 8?

(Note: I'm not interested in historic computer architectures using 18 or 36 bit words. It's genuinely a question about C as it is used today on current hardware; think systems with a C99 or later implementation).

like image 881
Jens Avatar asked Aug 19 '15 09:08

Jens


People also ask

Is sizeof char guaranteed to be 1?

Even if you think of a “character” as a multi-byte thingy, char is not. sizeof(char) is always exactly 1. No exceptions, ever.

Is a char always 1 byte?

"char" has always been a misspelling of "byte" in C. sizeof(char) has to be 1, but char doesn't have to be 1 byte in size. It's more correct to say that sizeof(foo) returns a result relative to sizeof(char).


2 Answers

TMS320C28x DSP from Texas Instruments has a byte with 16 bits.

Documentation for the compiler specifies CHAR_BIT as 16 on page 101.

This appears to be a modern processor (currently being sold), compilers supporting C99 and C++03.

like image 160
2501 Avatar answered Nov 02 '22 04:11

2501


Another example is Analog Devices' SHARC processor family. Its C implementation, CrossCore Embedded Studio, has CHAR_BIT == 32 and claims to provide freestanding C99 and C++11 conformance.

like image 31
a3f Avatar answered Nov 02 '22 05:11

a3f