thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Eggert <daniel.egg...@umzugsagenten.de>
Subject C strict aliasing rules
Date Wed, 28 Mar 2012 09:53:05 GMT
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


Mime
View raw message