You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Daniel Eggert <da...@umzugsagenten.de> on 2012/03/28 11:53:05 UTC
C strict aliasing rules
The Cocoa code has this in TBinaryProtocol:
- (void) writeDouble: (double) value
{
// spit out IEEE 754 bits - FIXME - will this get us in trouble on
// PowerPC?
[self writeI64: *((int64_t *) &value)];
}
this should be changed to
- (void) writeDouble: (double) value
{
// spit out IEEE 754 bits - FIXME - will this get us in trouble on
// PowerPC?
union {
int64_t i64;
double d;
} u;
u.d = value;
[self writeI64: u.i64];
}
since the current code violates C strict aliasing rules -- it works but it's undefined behavior.
C.f. <http://labs.qt.nokia.com/2011/06/10/type-punning-and-strict-aliasing/>
Daniel
Re: C strict aliasing rules
Posted by Jake Farrell <jf...@apache.org>.
If you would like to contribute a patch for this please see
http://thrift.apache.org/docs/HowToContribute/
On Wednesday, March 28, 2012, Richard Salz wrote:
> Is Cocoa C?
>
> --
> STSM, WebSphere Appliance Architect
> https://www.ibm.com/developerworks/mydeveloperworks/blogs/soma/
>
>
Re: C strict aliasing rules
Posted by Richard Salz <rs...@us.ibm.com>.
Is Cocoa C?
--
STSM, WebSphere Appliance Architect
https://www.ibm.com/developerworks/mydeveloperworks/blogs/soma/