Problem with string initializer
Andreas Schwab
schwab@suse.de
Thu Jun 29 02:53:00 GMT 2000
Horst von Brand <vonbrand@inf.utfsm.cl> writes:
|> 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:
Note that in C the above code is perfectly valid.
Andreas.
--
Andreas Schwab "And now for something
SuSE Labs completely different."
Andreas.Schwab@suse.de
SuSE GmbH, Schanzäckerstr. 10, D-90443 Nürnberg
More information about the Gcc-bugs
mailing list