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

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

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12744) datafilelist shouldn't return const char **
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 9 Apr 2005 20:41:03 -0700
Reply-to: bugs@xxxxxxxxxxx

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

> [bhudson - Sat Apr 09 02:19:02 2005]:
> 
> 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 *).

So you would think.  You'd also think you can implcitly cast from char**
to const char**.

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

That doesn't seem to work.

const char * const *get_soundset_list(void)
{
  static const char * const *audio_list = NULL;

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

  return audio_list;
}

audio.c: In function `get_soundset_list':
audio.c:91: warning: assignment from incompatible pointer type

jdorje@devon:~/src/freeciv/freeciv/client$ gcc --version
gcc (GCC) 3.4.4 20050314 (prerelease) (Debian 3.4.3-12)

-jason




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