Selaa lähdekoodia

Fixed warning "unused variable" with GCC 4.4 (issue #912)

Benoit Blanchon 7 vuotta sitten
vanhempi
sitoutus
ae2bfee0b1
2 muutettua tiedostoa jossa 8 lisäystä ja 12 poistoa
  1. 5 0
      CHANGELOG.md
  2. 3 12
      src/ArduinoJson/TypeTraits/FloatTraits.hpp

+ 5 - 0
CHANGELOG.md

@@ -1,6 +1,11 @@
 ArduinoJson: change log
 =======================
 
+HEAD
+----
+
+* Fixed warning "unused variable" with GCC 4.4 (issue #912)
+
 v5.13.4
 -------
 

+ 3 - 12
src/ArduinoJson/TypeTraits/FloatTraits.hpp

@@ -99,12 +99,8 @@ struct FloatTraits<T, 8 /*64bits*/> {
   // 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<T*>(&bits);
   }
 };
 
@@ -151,12 +147,7 @@ struct FloatTraits<T, 4 /*32bits*/> {
   }
 
   static T forge(uint32_t bits) {
-    union {
-      uint32_t integerBits;
-      T floatBits;
-    };
-    integerBits = bits;
-    return floatBits;
+    return *reinterpret_cast<T*>(&bits);
   }
 
   static T nan() {