From ad4489043b1d45476e0bdcfc046f4b8b15e1cbce Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Tue, 13 May 2014 17:48:47 +0100 Subject: [PATCH] =?UTF-8?q?Unanonymised=20unions=20to=20avoid=20breaking?= =?UTF-8?q?=20on=20compilers=20that=20don=E2=80=99t=20support=20them=20-?= =?UTF-8?q?=20e.g.=20GCC=204.3=20and=204.4=20-=20fixes=20#281?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/internal/catch_tostring.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/include/internal/catch_tostring.h b/include/internal/catch_tostring.h index d6c2fcf..25faa2a 100644 --- a/include/internal/catch_tostring.h +++ b/include/internal/catch_tostring.h @@ -84,25 +84,25 @@ namespace Detail { enum Arch { Big, Little }; static Arch which() { - union { + union _{ int asInt; char asChar[sizeof (int)]; - }; + } u; - asInt = 1; - return ( asChar[sizeof(int)-1] == 1 ) ? Big : Little; + u.asInt = 1; + return ( u.asChar[sizeof(int)-1] == 1 ) ? Big : Little; } }; // Writes the raw memory into a string, considering endianness template std::string rawMemoryToString( T value ) { - union { + union _ { T typedValue; unsigned char bytes[sizeof(T)]; - }; + } u; - typedValue = value; + u.typedValue = value; std::ostringstream oss; oss << "0x"; @@ -113,7 +113,7 @@ namespace Detail { end = inc = -1; } for( ; i != end; i += inc ) - oss << std::hex << std::setw(2) << std::setfill('0') << (unsigned int)bytes[i]; + oss << std::hex << std::setw(2) << std::setfill('0') << (unsigned int)u.bytes[i]; return oss.str(); }