Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2005:
[Freeciv-Dev] Re: (PR#12744) datafilelist shouldn't return const char **
Home

[Freeciv-Dev] Re: (PR#12744) datafilelist shouldn't return const char **

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#12744) datafilelist shouldn't return const char **
From: "Benoit Hudson" <bh@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 13 Apr 2005 13:04:44 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12744 >

On Sat, Apr 09, 2005 at 08:41:03PM -0700, Jason Short wrote:
> <URL: http://bugs.freeciv.org/Ticket/Display.html?id=12744 >
> > const char ** is almost never what you want: it's an array of constant
> > strings: you can't change a character, but you can change what string
> > you're pointing to.  Instead you want const char * const *: a constant
> > array of constant strings.  Accordingly, you can do the implicit cast
> > from (char **) to (const char * const *).
>
> So you would think.  You'd also think you can implcitly cast from char**
> to const char**.

Actually, no -- that would allow you to type-safely assign a const char*
to a char* and then modify it.  A good explanation lies at:
    http://www.parashift.com/c++-faq-lite/const-correctness.html#faq-18.17
(C/C++ is irrelevant here; the same argument holds in any language with
const modifiers and pointers or arrays).

> > audio_list should be const char * const *; then the cast goes away.
> > Same with the other case in the patch.
>
> That doesn't seem to work.

Fascinating.  I can't explain that except to say that C is being
overstrict.

cat > foo.c << EOF
void foo(void) {
    int **xpp;
    int const * const * xPP;
    xPP = xpp;
}
EOF
ln -s foo.c foo.cpp

# warning: assignment from incompatible pointer type
gcc -c foo.c

# no problem here
gcc -c foo.cpp





[Prev in Thread] Current Thread [Next in Thread]