/ Published in: C
You can find out the word sizes and endianness of a device by compiling the following program with a cross compiler and looking at the executable with the `strings` program or a hex editor. The `TESTIF` macro puts a copy of the statement to test and its truth value into a string which will be present in the exe. This helps if you do not have such a device handy, or if it is cumbersome to access (requires loading firmware etc.).
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#include <stdio.h> #include <endian.h> #define TESTIF(a) printf((a)? (#a ": TRUE") : (#a ": FALSE")); int main(int argc, char **argv) { TESTIF(sizeof(short) == 2) TESTIF(sizeof(int) == 4) TESTIF(sizeof(long) == 4) TESTIF(sizeof(long long) == 8) TESTIF(sizeof(void*) == 4) TESTIF(__BYTE_ORDER == __LITTLE_ENDIAN) }