Initialisation of Character Arrays
Paul D. Smith
pds at lemming.webo.dg.com
Fri Nov 16 03:20:25 AEST 1990
[] Consider the following code:
[] static char s1[] = "String One";
[] static unsigned char s2[] = "String Two";
[] static signed char s3[] = "String Three";
[...]
[] gcc -c -ansi -pedantic u.c
[] u.c:2: warning: ANSI C forbids string initializer except for `char' elements
[] u.c:3: warning: ANSI C forbids string initializer except for `char' elements
[...] Paragraph 3.5.7 of the ANSI Standard says:
[] An array of character type may be initialized by a character string
[] literal, optionally enclosed in braces. Successive characters of the
[] character string literal ... initialize the elements of the array.
[] The question is, does the code above comply with the Standard?
I had the same question when I got that same error. I also was not
able to find anything truly specific (all I've got is K&R II). In
Section A8.7, p. 219, you can find the above quote (almost verbatim),
and also the following:
... a wide character literal may initialize an array of type
`wchar_t'.
It's unfortunate the standard says `character' instead of `type char'
if they didn't mean to include explicitly signed or unsigned chars; in
light of the specific reference to `wchar_t' type I assumed that if
they had not meant to include signed and unsigned chars they would
have been more precise ...
But, I changed my code anyway ... a pain, but I hate warnings ...
--
paul
-----
------------------------------------------------------------------
| Paul D. Smith | pds at lemming.webo.dg.com |
| Data General Corp. | |
| Network Services Development | "Pretty Damn S..." |
| Open Network Applications Department | |
------------------------------------------------------------------
More information about the Comp.std.c
mailing list