strict-aliasing rule

This commit is contained in:
frsyuki 2010-01-20 14:46:54 +09:00
parent 1066bb38a8
commit d8212ad620
2 changed files with 12 additions and 12 deletions

View File

@ -554,19 +554,19 @@ if(sizeof(unsigned long long) == 2) {
msgpack_pack_inline_func(_float)(msgpack_pack_user x, float d) msgpack_pack_inline_func(_float)(msgpack_pack_user x, float d)
{ {
union { char buf[4]; uint32_t num; } f; union { float f; uint32_t i; } mem;
*((float*)&f.buf) = d; // FIXME mem.f = d;
unsigned char buf[5]; unsigned char buf[5];
buf[0] = 0xca; *(uint32_t*)&buf[1] = _msgpack_be32(f.num); buf[0] = 0xca; *(uint32_t*)&buf[1] = _msgpack_be32(mem.i);
msgpack_pack_append_buffer(x, buf, 5); msgpack_pack_append_buffer(x, buf, 5);
} }
msgpack_pack_inline_func(_double)(msgpack_pack_user x, double d) msgpack_pack_inline_func(_double)(msgpack_pack_user x, double d)
{ {
union { char buf[8]; uint64_t num; } f; union { double f; uint64_t i; } mem;
*((double*)&f.buf) = d; // FIXME mem.f = d;
unsigned char buf[9]; unsigned char buf[9];
buf[0] = 0xcb; *(uint64_t*)&buf[1] = _msgpack_be64(f.num); buf[0] = 0xcb; *(uint64_t*)&buf[1] = _msgpack_be64(mem.i);
msgpack_pack_append_buffer(x, buf, 9); msgpack_pack_append_buffer(x, buf, 9);
} }

View File

@ -222,13 +222,13 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
//case CS_ //case CS_
//case CS_ //case CS_
case CS_FLOAT: { case CS_FLOAT: {
union { uint32_t num; char buf[4]; } f; union { uint32_t i; float f; } mem;
f.num = PTR_CAST_32(n); // FIXME mem.i = PTR_CAST_32(n);
push_fixed_value(_float, *((float*)f.buf)); } push_fixed_value(_float, mem.f); }
case CS_DOUBLE: { case CS_DOUBLE: {
union { uint64_t num; char buf[8]; } f; union { uint64_t i; double f; } mem;
f.num = PTR_CAST_64(n); // FIXME mem.i = PTR_CAST_64(n);
push_fixed_value(_double, *((double*)f.buf)); } push_fixed_value(_double, mem.f); }
case CS_UINT_8: case CS_UINT_8:
push_fixed_value(_uint8, (uint8_t)PTR_CAST_8(n)); push_fixed_value(_uint8, (uint8_t)PTR_CAST_8(n));
case CS_UINT_16: case CS_UINT_16: