diff --git a/rmw_cyclonedds_cpp/include/rmw_cyclonedds_cpp/serdes.hpp b/rmw_cyclonedds_cpp/include/rmw_cyclonedds_cpp/serdes.hpp index 0fb3954..dfbe01c 100755 --- a/rmw_cyclonedds_cpp/include/rmw_cyclonedds_cpp/serdes.hpp +++ b/rmw_cyclonedds_cpp/include/rmw_cyclonedds_cpp/serdes.hpp @@ -411,18 +411,22 @@ public: } inline void print(float & x) { + union { uint32_t u; float f; } tmp; align(sizeof(x)); - uint32_t z = *reinterpret_cast(data + pos); - if (swap_bytes) {z = bswap4u(z);} - prtf(&buf, &bufsize, "%f", *reinterpret_cast(&z)); + tmp.u = *reinterpret_cast(data + pos); + if (swap_bytes) {tmp.u = bswap4u(tmp.u);} + static_cast(tmp.u); + prtf(&buf, &bufsize, "%f", tmp.f); pos += sizeof(x); } inline void print(double & x) { + union { uint64_t u; double f; } tmp; align(sizeof(x)); - uint64_t z = *reinterpret_cast(data + pos); - if (swap_bytes) {z = bswap8u(z);} - prtf(&buf, &bufsize, "%f", *reinterpret_cast(&z)); + tmp.u = *reinterpret_cast(data + pos); + if (swap_bytes) {tmp.u = bswap8u(tmp.u);} + static_cast(tmp.u); + prtf(&buf, &bufsize, "%f", tmp.f); pos += sizeof(x); } inline uint32_t get32()