GNOME Bugzilla – Bug 584670
proper GStaticMutex usage generates warning during compilation
Last modified: 2009-06-03 12:55:18 UTC
Please describe the problem: Using GStaticMutex in my code results in gcc warning "dereferencing type-punned pointer will break strict-aliasing rules are generated". Steps to reproduce: 1. make some program using GStaticMutex 2. compile with gcc -fstrict-aliasing -Wstrict-aliasing Actual results: warning: dereferencing type-punned pointer will break strict-aliasing rules Expected results: no warning Does this happen every time? yes Other information: simple example: -------- ex.c -------------------- #include <glib.h> int main() { g_thread_init(NULL); static GStaticMutex mutex = G_STATIC_MUTEX_INIT; g_static_mutex_lock (&mutex); g_static_mutex_unlock (&mutex); return 0; } ----------------------------- gcc -Wall -fstrict-aliasing -Wstrict-aliasing `pkg-config --cflags glib-2.0` -o ex ex.c `pkg-config --libs glib-2.0 gthread-2.0` => ex.c: In function 'main': ex.c:7: warning: dereferencing type-punned pointer will break strict-aliasing rules ex.c:8: warning: dereferencing type-punned pointer will break strict-aliasing rules I thing the problem is casting in g_static_mutex_* macros
*** This bug has been marked as a duplicate of 316221 ***