This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Problem with string initializer
- To: Manfred Hollstein <manfred dot h at gmx dot net>
- Subject: Re: Problem with string initializer
- From: Horst von Brand <vonbrand at inf dot utfsm dot cl>
- Date: Wed, 28 Jun 2000 15:53:28 -0400
- cc: Andreas Schwab <schwab at suse dot de>, gcc-bugs at gcc dot gnu dot org
Manfred Hollstein <manfredh@redhat.com> said:
> On Wed, 28 June 2000, 15:28:27 -0400, vonbrand@inf.utfsm.cl wrote:
> > Andreas Schwab <schwab@suse.de> said:
> > > The following input to the C++ compiler will result in an error:
> > > $ cat string.cc
> > > char x[] = {"asdf"};
> > > $ g++ -v string.cc
> >
> > [...]
> >
> > > string.cc:1: initializer-string for array of chars is too long
> > >
> > > The error does not occur if the braces are omitted.
> > Hummm... it should probably complain that you are trying to initialize a
> > char (x[0]) with a const char * ("asdf"). If there are no braces, there is
> > no error.
> You're absolutely right, that was my immediate response; BUT, then
> at least gcc-2.95.2 is wrong, which compiles this without notice...
gcc-2.95.2 is wrong then.
gcc-2.95.3-0.20000517 (from rawhide) doesn't complain either, not even with
-Wall (as gcc or as g++). It does complain (as it should) for:
char ss[] = "12345";
char x[] = {ss};
OTOH, gcc from CVS 20000627 doesn't complain, but g++ does:
/tmp/tst.c:1: initializer-string for array of chars is too long
The message is clearly wrong. Mixed up error messages, perhaps?
--
Dr. Horst H. von Brand mailto:vonbrand@inf.utfsm.cl
Departamento de Informatica Fono: +56 32 654431
Universidad Tecnica Federico Santa Maria +56 32 654239
Casilla 110-V, Valparaiso, Chile Fax: +56 32 797513