6 cc byteorder.c -o byteorder || exit 1
7 echo successfully compiled
11 /* Coypright (C) 1999-2003 Salvatore Sanfilippo */
15 * 0.2 add Strchr, so it's possibile remove string.h
16 * 0.3 more portable thx to Pancrazio De Mauro 'TrantIT'!!!
17 * 0.4 better debug output
20 /* $Id: byteorder.c,v 1.2 2003/09/01 00:22:06 antirez Exp $ */
24 char *Strchr(char *s, char c)
33 int main(int argc, char **argv)
35 unsigned int test = 1;
37 int macro = 0, debug = 0, help = 0, j;
39 for (j = 1; j < argc; j++) {
40 if (Strchr(argv[j], 'm')) macro = 1;
41 if (Strchr(argv[j], 'd')) debug = 1;
42 if (Strchr(argv[j], 'h')) help = 1;
46 printf( "-m macro output\n"
52 x = (unsigned char*) &test;
56 printf("__BIG_ENDIAN_BITFIELD\n");
58 printf("big endian\n");
60 else if (*x == 0x01) {
62 printf("__LITTLE_ENDIAN_BITFIELD\n");
64 printf("little endian\n");
66 printf("\nWARNING!!! byteorder exception\n\n");
71 printf("sizeof(unsigned int) = %d\n", sizeof(unsigned int));
72 printf("unsigned int test = 1;\n");
73 printf("in memory as: ");
74 for (j = 0; j < sizeof(unsigned int); j++)
75 printf("%02x ", x[j]);