Revision: 48823
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at July 11, 2011 06:08 by deepsoul
Initial Code
#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) }
Initial URL
Initial Description
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.).
Initial Title
Determine word sizes by cross-compiling only
Initial Tags
Initial Language
C