Question on strict aliasing in C.

kevin diggs diggskevin38@gmail.com
Tue Jul 5 22:56:00 GMT 2011


Hi,

On Mon, Jul 4, 2011 at 12:07 PM, Andrew Haley <aph@redhat.com> wrote:
>
> It's not.  Tey're wrong, you're right.
>
> Hope this helps.  :-)
>
> Andrew.
>

What about this:

#include <math.h>

#define MASK ((unsigned short) 0x8000)

double copysign (double x, double y)
{
unsigned short * const py = (unsigned short*)(char*)&y + 3;

	return fabs(x)*(*py&MASK?-1.0:1.0);
}

kevin



More information about the Gcc-help mailing list