dereferencing type-punned pointer will break strict-aliasing rules

common at gmx.ch common at gmx.ch
Sat Oct 11 15:46:38 CEST 2008


Hi,

first, libev is lovely, I really appreciate it.


Now, my problem:

take the example code from the manpage and compile it using:

gcc -DHAVE_CONFIG_H -I. -I..    -I/opt/libev/include/ -I../include -I .. 
-Wall -g -g -O2 -MT ev.o -MD -MP -MF ev.Tpo -c -o ev.o `test -f 'ev.c' 
|| echo './'`ev.c

this is line is created by autotools, so more or less a default.
One might have to adjust the /opt/libev pathes.


I get:

ev.c: In Funktion »main«:
ev.c:45: Warnung: Dereferenzierung eines Type-Pun-Zeigers verletzt 
strict-aliasing-Regeln

line 45 is
      ev_timer_init (&timeout_watcher, timeout_cb, 5.5, 0.);

as I added stdio.h to get rid of the puts warning.

gcc -Wall -o ev ev.c
does not give this warning.


my build system:

gcc -v
Es werden eingebaute Spezifikationen verwendet.
Ziel: x86_64-linux-gnu
Konfiguriert mit: ../src/configure -v 
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr 
--enable-shared --with-system-zlib --libexecdir=/usr/lib 
--without-included-gettext --enable-threads=posix --enable-nls 
--with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2 
--enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc 
--enable-mpfr --enable-checking=release --build=x86_64-linux-gnu 
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread-Modell: posix
gcc-Version 4.2.3 (Ubuntu 4.2.3-2ubuntu7)


uname -a
Linux hostname 2.6.24-19-generic #1 SMP Wed Aug 20 17:53:40 UTC 2008 
x86_64 GNU/Linux


Problem is, I tend to use -Wall -Werror, as the compiler is my friend 
and it usually pays of taking care if he complains, therefore I can't 
compile code with libev timers.
Of course I could use -fno-strict-aliasing, but that does not fix the 
problems root cause.


For now I'll have to disable -Werror, but I'd prefer a real working 
solution.


MfG
Markus



More information about the libev mailing list