- more updates to support big endian

This commit is contained in:
Mark Vejvoda
2012-11-01 16:25:15 +00:00
parent c1ec7a395c
commit 56bcd62d88
2 changed files with 13 additions and 8 deletions

View File

@@ -17,14 +17,18 @@
namespace Shared{ namespace PlatformByteOrder {
template<class T> T EndianReverse(T t) {
unsigned char uc[sizeof t];
memcpy(uc, &t, sizeof t);
// unsigned char uc[sizeof t];
// memcpy(uc, &t, sizeof t);
//
// for (unsigned char *b = uc, *e = uc + sizeof(T) - 1; b < e; ++b, --e) {
// std::swap(*b, *e);
// }
// memcpy(&t, uc, sizeof t);
// return t;
for (unsigned char *b = uc, *e = uc + sizeof(T) - 1; b < e; ++b, --e) {
std::swap(*b, *e);
}
memcpy(&t, uc, sizeof t);
return t;
char& raw = reinterpret_cast<char&>(t);
std::reverse(&raw, &raw + sizeof(T));
return t;
}
static bool isBigEndian() {