Initialisation of unsigned strings

eru at tnvsu1.tele.nokia.fi eru at tnvsu1.tele.nokia.fi
Fri Jul 28 03:56:13 AEST 1989


I often use the "unsigned char" type to represent characters to avoid the
nonsense with negative letters (characters with the MSB set are commonly used
in ordinary text here). Thus sometimes arrays of "unsigned char" are initial-
ised with string constants. Then one day I compiled some such code with Gnu-C
with the switches -ansi -pedantic and it said that my initialisations are
non-ANSI.

First I thought that gcc was being too pedantic, but unfortunately the May
1988 draft seems to agree: 3.1.2.5 classifies "unsigned char" as an unsigned
integer type, and 3.5.7 says that an array of character type may be initialised
by a character string literal. Why could it not say "array of plain, signed or
unsigned char"?

Thus it appears that those who want to program in pure ANSI-C without the
fuzziness introduced by the implementation-dependent behaviour of plain char
lose the convenience of string literals. This ought to be changed in the
next version of the standard (if there ever is one). Prior art exists:
all the C-compilers with unsigned char that I have used compile this usage
of string literals.


Erkki Ruohtula    ! Nokia Telecommunications
eru at tele.nokia.fi ! P.O. Box 33 SF-02601 Espoo, Finland



More information about the Comp.std.c mailing list