mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
Unanonymised unions to avoid breaking on compilers that don’t support them
- e.g. GCC 4.3 and 4.4 - fixes #281
This commit is contained in:
parent
4e044ed4b1
commit
ad4489043b
@ -84,25 +84,25 @@ namespace Detail {
|
|||||||
enum Arch { Big, Little };
|
enum Arch { Big, Little };
|
||||||
|
|
||||||
static Arch which() {
|
static Arch which() {
|
||||||
union {
|
union _{
|
||||||
int asInt;
|
int asInt;
|
||||||
char asChar[sizeof (int)];
|
char asChar[sizeof (int)];
|
||||||
};
|
} u;
|
||||||
|
|
||||||
asInt = 1;
|
u.asInt = 1;
|
||||||
return ( asChar[sizeof(int)-1] == 1 ) ? Big : Little;
|
return ( u.asChar[sizeof(int)-1] == 1 ) ? Big : Little;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Writes the raw memory into a string, considering endianness
|
// Writes the raw memory into a string, considering endianness
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::string rawMemoryToString( T value ) {
|
std::string rawMemoryToString( T value ) {
|
||||||
union {
|
union _ {
|
||||||
T typedValue;
|
T typedValue;
|
||||||
unsigned char bytes[sizeof(T)];
|
unsigned char bytes[sizeof(T)];
|
||||||
};
|
} u;
|
||||||
|
|
||||||
typedValue = value;
|
u.typedValue = value;
|
||||||
|
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << "0x";
|
oss << "0x";
|
||||||
@ -113,7 +113,7 @@ namespace Detail {
|
|||||||
end = inc = -1;
|
end = inc = -1;
|
||||||
}
|
}
|
||||||
for( ; i != end; i += inc )
|
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();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user