Initialisation of unsigned strings
david.f.prosser
dfp at cbnewsl.ATT.COM
Fri Jul 28 22:36:37 AEST 1989
In article <438 at mjolner.tele.nokia.fi> eru at tnvsu1.tele.nokia.fi () writes:
>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.
The pANS requires that arrays of any of the three char types can be
initialized with a string literal. The definition of *character type*
can be found in section 3.1.2.5 (like most of the other mumble types):
The three types char, signed char, and unsigned char are
collectively called the character types.
However, one cannot initialize a pointer to a signed or unsigned char
with a string literal (without a cast).
char ca[] = "abc"; /* valid */
signed sca[] = "abc"; /* valid */
unsigned uca[] = "abc"; /* valid */
char *cp = "abc"; /* valid */
signed char *scp = "abc"; /* invalid */
unsigned char *ucp = "abc"; /* invalid */
signed char *p = (signed char *)"abc"; /* valid */
unsigned char *p = (unsigned char *)"abc"; /* valid */
Dave Prosser ...not an official X3J11 answer...
More information about the Comp.std.c
mailing list