[Project-managers] Re: [Coin-tlc] lots of things to test
Laszlo Ladanyi
ladanyi at us.ibm.com
Sun Sep 30 21:02:26 EDT 2007
Just a note...
There are quite a number of warnings of the kind:
"dereferencing type-punned pointer will break strict-aliasing rules".
These warnings are there, because we use -fstrict-alias when gcc is used to
allow gcc to optimize better. However, I have found examples on the web where
a code for which this warning was emitted had actually been miscompiled.
So what should we do? As a short term solution we can just remove
-fstrict-alias, but it'd be better to get rid of the warning. It comes up
when, e.g., a double* is assigned to an int* or any type of pointer is cast to
a void*. The way to get rid of the warning is to use unions.
For example the following code triggers the warning (when the first part is
taken):
int hash(double value)
{
#if sizeof(int)*2 == sizeof(double)
int *xx = (int*)(&value)
xx[0] += xx[1];
return xx[0];
#else
return (int) value;
#endif
}
But the equivalent code does not (and I don't think this is any slower, in
fact it may well be faster since no memory dereferencing is needed, hence
the whole thing can even be executed in registers):
int hash(double value)
{
#if sizeof(int)*2 == sizeof(double)
union { double d; int i[2]; } xx;
xx.d = value;
xx.i[0] += xx.i[1];
return xx.i[0];
#else
return (int) value;
#endif
}
Any thoughts?
Cheers,
--Laci
More information about the Project-managers
mailing list