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: Fri, 8 Apr 2005 19:19:02 -0700
Reply-to: bugs@xxxxxxxxxxx

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

On Fri, Apr 08, 2005 at 08:55:56AM -0700, Jason Short wrote:
> 
> <URL: http://bugs.freeciv.org/Ticket/Display.html?id=12744 >
> 
> The datafilelist function returns a "const char **".  But according to 
> the function comment:

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 *).

C has just about the ugliest type names in existance.

> In other words, the caller owns the return pointer, not the function. 
> However it's impossible to "correctly" free the return values because of 
> the const qualifier.  Basically, the const is wrong because since the 
> caller owns the data it can do whatever it wants with the data.

Just to be clear, I'm not contradicting this.

>    if (!audio_list) {
>      /* Note: this means you must restart the client after installing a new
>         soundset. */
> -    audio_list = datafilelist(SNDSPEC_SUFFIX);
> +    audio_list = (const char **)datafilelist(SNDSPEC_SUFFIX);

audio_list should be const char * const *; then the cast goes away.
Same with the other case in the patch.

        -- Benoît





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