This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: string is const char [] ?
- To: Alexandre Oliva <oliva at dcc dot unicamp dot br>
- Subject: Re: string is const char [] ?
- From: Kamil Iskra <kamil at dwd dot interkom dot pl>
- Date: Wed, 24 Jun 1998 15:07:30 +0200 (MET DST)
- cc: egcs at cygnus dot com, egcs-bugs at cygnus dot com
- Reply-To: Kamil Iskra <kamil at dwd dot interkom dot pl>
On 24 Jun 1998, Alexandre Oliva wrote:
> >> > char a1[] = "test not const";
> >> This line should cause egcs to flag an error.
> > Excuse me?! I missed the original mail, but do you really suggest that all
> > the programmers should suddenly switch to:
> > char a1[]={'t', 'e', 's', 't', ' ', 'n', 'o', 't', ' ', 'c', 'o', 'n',
> > 's', 't', '\0'};
> How about:
>
> const char a1[] = "test not const";
I didn't want a const array, I wanted a plain one, probably for a good
reason. Maybe I wanted to change some characters or append something to
it? Now, how should I do that to satisfy the standard and avoid the much
more error-prone standard array-initialisation syntax?
Don't get me wrong, I'm sure you know the standard far better than I do,
but are you SURE that it disallows this initialisation syntax? I find it
hard to believe, since first, I think this syntax is very common (at least
I use it quite often), and second, this syntax is fine in C, and C++ is
generally supposed to accept C code (I know, there are certain
incompatibilities, and, IIRC, there is even a list of them. Is this
particular incompatibility listed there?).
If the standard indeed does deliberately disallow this initialisation
syntax, I would vote that G++ allows it, preferably without any warnings
(unless compiling with -ansi, -pedantic or some such).
/ Kamil Iskra AmigaOS Linux/i386 Linux/m68k \
| GeekGadgets GCC maintainer UNIX system administrator |
| iskra@student.uci.agh.edu.pl kiskra@ernie.icslab.agh.edu.pl |
\ kamil@dwd.interkom.pl http://student.uci.agh.edu.pl/~iskra /