From ae2bfee0b14522255d014f90620a4b2e09f87753 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Thu, 28 Feb 2019 10:22:27 +0100 Subject: [PATCH] Fixed warning "unused variable" with GCC 4.4 (issue #912) --- CHANGELOG.md | 5 +++++ src/ArduinoJson/TypeTraits/FloatTraits.hpp | 15 +++------------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18240dc5..2096a8b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ ArduinoJson: change log ======================= +HEAD +---- + +* Fixed warning "unused variable" with GCC 4.4 (issue #912) + v5.13.4 ------- diff --git a/src/ArduinoJson/TypeTraits/FloatTraits.hpp b/src/ArduinoJson/TypeTraits/FloatTraits.hpp index b16344c8..f483c9fc 100644 --- a/src/ArduinoJson/TypeTraits/FloatTraits.hpp +++ b/src/ArduinoJson/TypeTraits/FloatTraits.hpp @@ -99,12 +99,8 @@ struct FloatTraits { // we use this function to workaround platforms with single precision literals // (for example, when -fsingle-precision-constant is passed to GCC) static T forge(uint32_t msb, uint32_t lsb) { - union { - uint64_t integerBits; - T floatBits; - }; - integerBits = (uint64_t(msb) << 32) | lsb; - return floatBits; + uint64_t bits = (uint64_t(msb) << 32) | lsb; + return *reinterpret_cast(&bits); } }; @@ -151,12 +147,7 @@ struct FloatTraits { } static T forge(uint32_t bits) { - union { - uint32_t integerBits; - T floatBits; - }; - integerBits = bits; - return floatBits; + return *reinterpret_cast(&bits); } static T nan() {