This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: string is const char [] ?


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]