This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: string is const char [] ?
- To: jeroen dobbelaere xe44 7682 <dobbelaj at access dot bel dot alcatel dot be>
- Subject: Re: string is const char [] ?
- From: Alexandre Oliva <oliva at dcc dot unicamp dot br>
- Date: 23 Jun 1998 20:12:34 -0300
- Cc: egcs-bugs at cygnus dot com, chorafad at access dot bel dot alcatel dot be
- References: <199806181105.NAA10911@btm15j.access>
jeroen dobbelaere xe44 7682 <dobbelaj@access.bel.alcatel.be> writes:
> An ordinary string literal has type "array of n __const__
> char" and static storage duration
> Is this a bug ?
Yes, egcs is wrong.
> char a1[] = "test not const";
This line should cause egcs to flag an error. The only
backward-compatibility provided in the standard is [conv.array]/2,
that allows string literals to be converted to non-const `char*'.
Hence, string literals cannot be used to initialize a char[]. At
least a warning should be issued in this case.
> f("test should be const");
This should select `f(char const*)' instead of `f(char*)', because
converting `char const[n]' to `char*' involves an additional
deprecated qualification conversion.
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil