Initialisation of Character Arrays

John Honniball bj at europa.inmos.co.uk
Thu Nov 15 05:29:37 AEST 1990


Consider the following code:

static          char s1[] = "String One";
static unsigned char s2[] = "String Two";
static signed   char s3[] = "String Three";

Just three initialised character arrays, right?  Now compile it with
GNU C (version 1.36):

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

So the compiler is complaining about the initialised 'unsigned' and
'signed' character arrays.  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?

________________________________________________________________
| John Honniball (BJ), INMOS Limited, 1000 Aztec West, Bristol |
| UK: bj at inmos.co.uk   Elsewhere: bj at inmos.com                 |



More information about the Comp.std.c mailing list