mirror of
https://github.com/glest/glest-source.git
synced 2025-08-11 19:04:00 +02:00
- more updates to support big endian
This commit is contained in:
@@ -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() {
|
||||
|
Reference in New Issue
Block a user