Created
August 23, 2020 21:27
-
-
Save Tricky1975/3fe3ab2571011a16896ceaf0c23ddb49 to your computer and use it in GitHub Desktop.
Just a little routine I whipped up to check if the system the code runs on is LittleEndian or not (now there ain't much BigEndian systems anymore as far as I know, but they are still there, I guess).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define Test_EndianCheck | |
typedef union { | |
unsigned char b[4]; | |
int i; | |
} ucheck; | |
namespace TrickyUnits{ | |
bool IsLittleEndian(){ | |
ucheck chk; | |
chk.i=256; | |
return chk.b[1]==1; | |
} | |
bool IsBigEndian() { return !IsLittleEndian();} | |
} | |
#ifdef Test_EndianCheck | |
#include <iostream> | |
using namespace TrickyUnits; | |
int main(){ | |
if (IsLittleEndian()) | |
std::cout << "System is LittleEndian\n"; | |
else | |
std::cout << "System is BigEndian\n"; | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment