prev up next   top/contents search

comp.lang.c FAQ list · Question 8.10

Q: I'm starting to think about multinational character sets, and I'm worried about the implications of making sizeof(char) be 2 so that 16-bit character sets can be represented.


A: If type char were made 16 bits, sizeof(char) would still be 1, and CHAR_BIT in <limits.h> would be 16, and it would simply be impossible to declare (or allocate with malloc) a single 8-bit object.

Traditionally, a byte is not necessarily 8 bits, but merely a smallish region of memory, usually suitable for storing one character. The C Standard follows this usage, so the bytes used by malloc and sizeof can be more than 8 bits. [footnote] (The Standard does not allow them to be less.)

To allow manipulation of multinational character sets without requiring an expansion of type char, ANSI/ISO C defines the ``wide'' character type wchar_t, and corresponding wide string literals, and functions for manipulating and converting strings of wide characters.

See also question 7.8.

References: ISO Sec. 5.2.1.2, Sec. 6.1.3.4, Sec. 6.1.4, Sec. 7.1.6, Sec. 7.10.7, Sec. 7.10.8
Rationale Sec. 2.2.1.2
H&S Sec. 2.7.3 pp. 29-30, Sec. 2.7.4 p. 33, Sec. 11.1 p. 293, Secs. 11.7,11.8 pp. 303-310


prev up next   contents search
about this FAQ list   about eskimo   search   feedback   copyright

Hosted by Eskimo North