Missing warning message

Zack Weinberg zackw@stanford.edu
Sat Feb 10 13:13:00 GMT 2001


On Sat, Feb 10, 2001 at 01:21:18PM -0700, Andrew Vaught wrote:
> While working on g95, we had an erroneous declaration that looked like:
> 
> 
> char array[] = { "a", "b", "c" };
> 
> Compiling with '-Wall -pedantic' gave no warnings of any sort.  Gcc missed
> the fact that the array elements are characters while the initialization
> elements are pointers to character.  gcc -v gives:
> 
> Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/specs
> gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)

gcc 2.97 20010105 gives

test.c:1: excess elements in char array initializer
test.c:1: (near initialization for `array')
test.c:1: excess elements in char array initializer
test.c:1: (near initialization for `array')

That is an error, not a warning.  Note that

char array[] = { "abc" };

is completely valid from the standard's point of view, equivalent to

char array[] = "abc";

although a case could be made for a warning here, on the grounds that
the programmer probably meant to write char *array[].

zw



More information about the Gcc-bugs mailing list