Created
April 29, 2016 04:55
-
-
Save mlabbe/889781de525139c5ed01dc96c25bf74c to your computer and use it in GitHub Desktop.
Endian detection in the preprocessor
This file contains hidden or 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
| // My goal is to perform endian detect in the preprocessor without | |
| // breaking C89 compatibility. YES, I know how rare big endian is in 2016. I don't care. | |
| #if (0xFF<<8) & 65280 | |
| # define LITTLE_ENDIAN | |
| #else | |
| # define BIG_ENDIAN | |
| #endif | |
| // The magic 65280 is a 16 bit int with eight ones followed by eight zeros, at least on little endian. | |
| // Comments? | |
| // Can anyone say whether the preprocessor emulates the enddianness of the target architecture in a cross compile? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment