Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!dg!fs06!pds From: pds@lemming.webo.dg.com (Paul D. Smith) Newsgroups: comp.std.c Subject: Re: Initialisation of Character Arrays Message-ID: Date: 15 Nov 90 16:20:25 GMT References: <12585@ganymede.inmos.co.uk> Sender: root@dg.dg.com Organization: NSDD/ONAD, Data General Corp., Westboro, MA Lines: 45 In-reply-to: bj@europa.inmos.co.uk's message of 14 Nov 90 18:29:37 GMT [] 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@lemming.webo.dg.com | | Data General Corp. | | | Network Services Development | "Pretty Damn S..." | | Open Network Applications Department | | ------------------------------------------------------------------