This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Missing warning message
- To: Zack Weinberg <zackw at stanford dot edu>
- Subject: Re: Missing warning message
- From: Andrew Vaught <andy at xena dot eas dot asu dot edu>
- Date: Sat, 10 Feb 2001 14:48:19 -0700 (MST)
- cc: gcc-bugs at gcc dot gnu dot org
On Sat, 10 Feb 2001, Zack Weinberg wrote:
> 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[].
In this case, the programmer actually meant to write:
char array[] = { 'a', 'b', 'c' };
the reason she didn't use
char array[] = "abc";
was because the table was an ascii-to-ebcdic-or-whatever table that has
lots of \0's at the lower end of the table. When gcc saw:
char array[] = { "a", "b", "c" };
It generated a pointer to "a", then cast it to a character without
complaining about the overflow and basically created an array of pointers
consisting solely of the low bytes of pointers.
But it looks like the newer gcc is handling this already as if she *did*
write:
char *array[] = { "a", "b", "c" };
You might try running the intended version with gcc 2.97:
char array[] = { 'a', 'b', 'c' };
to make sure that this works. It isn't the usual way of writing that, but
AFAIK it's legal.
Andy
----------------- XOLD(K,IC,I)=
Andy Vaught .... DO ITERS=1, 10 XOLD(K,IC,I)
andy@xena.eas.asu.edu | | /CALLMSOLVE(A,B,X,I,ITERS,TOL)+(RANNYU(0)
Arizona State University ======|WRITE(6,'(I5,2X,F12.6)')ITERS,TOL -HALF)
Tempe, Arizona USA OOOOOO \ENDDORETURN PARAMETER(ZERO=1.D0)*TENTH*DELTA