This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: problem with alias-safe code
>>>>> "Ulrich" == Ulrich Drepper <drepper@cygnus.com> writes:
Ulrich> Mark Mitchell <mark@markmitchell.com> writes:
>> Oh, dear. I always get bogged down in these GCC extensions.
>> I'm sure there's a good reason for them, but in this case why
>> not just write:
>>
>> double my_fabs (double x) { union u_t { double d; int i[2]; };
>> ((union u_t*) &x)->i[1] &= 0x7fffffff; return x; }
Ulrich> This works in the given case but in general such a
Ulrich> construct is used with an arbitrary value for the floating
Ulrich> point value. The situation is that I need macros which
Ulrich> extracts from a given floating point value the words. The
Ulrich> FP value can be a memory location like in the fabs
Ulrich> example, but it could also be a rvalue. The gcc extension
Ulrich> makes sure it works in either case.
OK, makes sense. Richard, I think your patch is OK, except for the
following nit: you make sure that the type being converted and the
union have the same size, but not the same alignment. Shouldn't you
check that, too? For example, casting an array of 8 characters to a
union containing a double might not be OK, right?
--
Mark Mitchell mark@markmitchell.com
Mark Mitchell Consulting http://www.markmitchell.com