This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Question on strict aliasing in C.
- From: Paul Smith <paul at mad-scientist dot net>
- To: Georg-Johann Lay <avr at gjlay dot de>
- Cc: Andrew Haley <aph at redhat dot com>, gcc-help at gcc dot gnu dot org
- Date: Mon, 04 Jul 2011 13:56:22 -0400
- Subject: Re: Question on strict aliasing in C.
- References: <4E11F0FC.7020601@gjlay.de> <4E11F35E.6050209@redhat.com> <4E11F5A1.1080204@gjlay.de>
- Reply-to: paul at mad-scientist dot net
On Mon, 2011-07-04 at 19:17 +0200, Georg-Johann Lay wrote:
> >> double copysign (double x, double y)
> >> {
> >> unsigned short * const px = (unsigned short*)(char*)&x + 3;
> >> unsigned short * const py = (unsigned short*)(char*)&y + 3;
I don't get why you have the (char*) cast here?
> >> *px = *px & ~MASK | *py & MASK;
> >> return x;
> >> }
> >>
> >> So I want to reassure me if the code is ok or not.
> >
> > It's not. Tey're wrong, you're right.
So let me ask: if you change the last line to:
return *px;
instead, is it now OK WRT aliasing rules?