This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: string is const char [] ?
- To: egcs at cygnus dot com
- Subject: Re: string is const char [] ?
- From: Oleg Zabluda <zabluda at math dot psu dot edu>
- Date: Wed, 24 Jun 1998 22:55:39 -0400 (EDT)
: On 23 Jun 1998, Alexandre Oliva wrote:
: > >> > char a1[] = "test not const";
: >
: > >> This line should cause egcs to flag an error.
: Kamil Iskra <kamil@dwd.interkom.pl> writes:
: > > Excuse me?! I missed the original mail, but do you really suggest that al
: > > the programmers should suddenly switch to:
: >
: > > char a1[]={'t', 'e', 's', 't', ' ', 'n', 'o', 't', ' ', 'c', 'o', 'n',
: > > 's', 't', '\0'};
: Alexandre Oliva writes:
: > How about:
: > const char a1[] = "test not const";
: Kamil is trying to initialize a char[], so your suggestion is irrelevant.
: Programmers must sometimes initialize a writable string, and the standard
: way to do this in C is exactly the way you claim is forbidden. This would
: need to be documented as a language incompatibility.
: I don't believe that you are correct, Alexandre. I think you are
: confusing assignment (where there is a conversion) with initialization.
: If the standard is unclear, this is a case where the committee should be
: asked to produce a clarification.
I think this is the rare case when Alexandre is confusing issues,
and the standard is very clear (8.5.2)
char a1[] = "test not const"; is definitely legal. What
is also legal, but deprecated is
char *a1 = "test not const";
This generates a warning when compiled with -Wwrite-strings.
Here is a real bug in egcs:
void f( char *) {}
voif f(const char *) {}
f("test not const"); // error in egcs. f(const char *) must be called,
// because the type of string literals now is
// array of n const char. However egcs calls
// f(char*). -Wwrite-strings has no effect.
// And even warning is surpressed.
Oleg.
--
Life is a sexually transmitted, 100% lethal disease.