I cannot compile the master branch with g++ 4.4 because of this commit:
https://github.com/zeromq/libzmq/commit/c995de65847d8a97dc75294fb1b9b6a057fd3c1d
I get errors like this:
options.cpp: In member function ‘int zmq::options_t::setsockopt(int,
const void*, size_t)’:
options.cpp:328:52: error: dereferencing type-punned pointer will break
strict-aliasing rules
Actually, these kind of errors is what the abovementioned commit is
trying to fix, but it did not get it right.
I can see three possible solutions:
1. As the only standards-compliant way "casting" between
pointer-to-object and pointer-to-function is through a union, the
zmq_monitor_fn type could be changed to something like:
typedef union
{
void *object;
void (*function)(void *s, int event, zmq_event_data_t *data);
} zmq_monitor_fn;
and the various places where the monitor function is used, must be
changed appropriately.
This is not a good solution because it creates an awkward API for
callback functions.
2. Add a separate zmq_setsockopt() that takes a pointer-to-function
instead of pointer-to-object.
It might be even better to add explicit getters and setters for the
various options, rather than having to rely on va_args to create a
"fake" overloading in C.
3. The problem with strict aliasining is more or less theoretical. Posix
requires that pointer-to-object and pointer-to-function must have the
same representation. We could therefore lower the strictness of the
aliasing checking for g++. I have attached a patch just in case.
diff --git a/acinclude.m4 b/acinclude.m4
index c5c2748..e4502d1 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -451,7 +451,7 @@ AC_DEFUN([LIBZMQ_LANG_STRICT], [{
xcxx)
# GCC, clang and ICC
if test "x$GXX" = "xyes" -o "x$libzmq_cv_[]_AC_LANG_ABBREV[]_clang_compiler" = "xyes"; then
- libzmq_cv_[]_AC_LANG_ABBREV[]_strict_flag="-pedantic"
+ libzmq_cv_[]_AC_LANG_ABBREV[]_strict_flag="-pedantic -Wstrict-aliasing=3"
elif test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler" = "xyes"; then
libzmq_cv_[]_AC_LANG_ABBREV[]_strict_flag="-strict-ansi"
# Sun studio
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev