dereferencing type-punned pointer warning

Johannes Hofmann <[email protected]>
Newsgroups gmane.comp.web.dillo.devel
Message-ID <[email protected]>
Hi,

line 135 in lout object.cc:
return ((int*)&value)[0] ^ ((int*)&value)[1];

causes the following error on 64bit systems for me:

warning: dereferencing type-punned pointer will
         break strict-aliasing rules

Can we replace it like this:

diff -r dd6f2d1eb15a lout/object.cc
--- a/lout/object.cc	Mon Jan 14 10:26:37 2013 -0300
+++ b/lout/object.cc	Mon Jan 14 21:56:46 2013 +0100
@@ -21,6 +21,7 @@
 
 #include "object.hh"
 #include <stdio.h>
+#include <stdint.h>
 #include <config.h>
 
 namespace lout {
@@ -132,7 +133,7 @@
    // Combine both parts of the pointer value *itself*, not what it
    // points to, by first referencing it (operator "&"), then
    // dereferencing it again (operator "[]").
-   return ((int*)&value)[0] ^ ((int*)&value)[1];
+   return ((intptr_t)value >> 32) ^ ((intptr_t)value);
 #endif
 }
 
Cheers,
Johannes
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.