Re: type-punning warnings with optimizations turned on?



On Fri, 2007-07-06 at 16:47 +0100, jcupitt gmail com wrote:
I think this is a gcc 4.1 issue. I found I couldn't cast from a Thing
*x[] to a void ** in one step without triggering a warning like this.
If I cast to void* and then to void **, all was well.

Anyway, insert a mysterious extra cast and the warnings vanish. Try
compiling this with -O2 -Wall and you'll see only one line triggers a
warning.

============
void
test (void **base)
{
}

int
main ()
{
  int *thing[3];

  test ((void **) thing);
  test ((void **) ((void *) thing));

  return (0);
}
==============

(now someone will tell me the compiler is correct and casting "int
*x[]" to "void **" is indeed wrong :-)

That's interesting. Unfortunately for me, I don't have a lot of casting
options. Really, in this case:

    void test() {
        static GStaticMutex mutex;
        g_static_mutex_init(&mutex);
        g_static_mutex_lock(&mutex);   /* warning */
        g_static_mutex_unlock(&mutex); /* warning */
        g_static_mutex_free(&mutex);
    }

what's there to cast? I would have to dig into GLib source and figure
out what GStaticMutex really was and cast to that, I suppose.

-Alan




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]