diff --git a/include/internal/catch_tostring.cpp b/include/internal/catch_tostring.cpp index 2f66f49d..a289c341 100644 --- a/include/internal/catch_tostring.cpp +++ b/include/internal/catch_tostring.cpp @@ -38,13 +38,11 @@ namespace Detail { enum Arch { Big, Little }; static Arch which() { - union _{ - int asInt; - char asChar[sizeof (int)]; - } u; - - u.asInt = 1; - return ( u.asChar[sizeof(int)-1] == 1 ) ? Big : Little; + int one = 1; + // If the lowest byte we read is non-zero, we can assume + // that little endian format is used. + auto value = *reinterpret_cast(&one); + return value ? Little : Big; } }; } @@ -241,13 +239,13 @@ std::string StringMaker::convert(std::nullptr_t) { } int StringMaker::precision = 5; - + std::string StringMaker::convert(float value) { return fpToString(value, precision) + 'f'; } int StringMaker::precision = 10; - + std::string StringMaker::convert(double value) { return fpToString(value, precision); }