1 /* $Id$ */ |
1 /* $Id$ */ |
|
2 |
|
3 /** @file endian_check.cpp |
|
4 * This pretty simple file checks if the system is LITTLE_ENDIAN or BIG_ENDIAN |
|
5 * it does that by putting a 1 and a 0 in an array, and read it out as one |
|
6 * number. If it is 1, it is LITTLE_ENDIAN, if it is 256, it is BIG_ENDIAN |
|
7 * |
|
8 * After that it outputs the contents of an include files (endian.h) |
|
9 * that says or TTD_LITTLE_ENDIAN, or TTD_BIG_ENDIAN. Makefile takes |
|
10 * care of the real writing to the file. */ |
2 |
11 |
3 #include <stdio.h> |
12 #include <stdio.h> |
4 #include <string.h> |
13 #include <string.h> |
5 |
|
6 // This pretty simple file checks if the system is LITTLE_ENDIAN or BIG_ENDIAN |
|
7 // it does that by putting a 1 and a 0 in an array, and read it out as one |
|
8 // number. If it is 1, it is LITTLE_ENDIAN, if it is 256, it is BIG_ENDIAN |
|
9 // |
|
10 // After that it outputs the contents of an include files (endian.h) |
|
11 // that says or TTD_LITTLE_ENDIAN, or TTD_BIG_ENDIAN. Makefile takes |
|
12 // care of the real writing to the file. |
|
13 |
14 |
14 int main (int argc, char *argv[]) { |
15 int main (int argc, char *argv[]) { |
15 unsigned char EndianTest[2] = { 1, 0 }; |
16 unsigned char EndianTest[2] = { 1, 0 }; |
16 int force_BE = 0, force_LE = 0, force_PREPROCESSOR = 0; |
17 int force_BE = 0, force_LE = 0, force_PREPROCESSOR = 0; |
17 |
18 |
29 } else { |
30 } else { |
30 if (force_BE == 1) { |
31 if (force_BE == 1) { |
31 printf("#define TTD_BIG_ENDIAN\n"); |
32 printf("#define TTD_BIG_ENDIAN\n"); |
32 } else { |
33 } else { |
33 if (force_PREPROCESSOR == 1) { |
34 if (force_PREPROCESSOR == 1) { |
34 // adding support for universal binaries on OSX |
35 /** adding support for universal binaries on OSX |
35 // Universal binaries supports both PPC and x86 |
36 * Universal binaries supports both PPC and x86 |
36 // If a compiler for OSX gets this setting, it will always pick the correct endian and no test is needed |
37 * If a compiler for OSX gets this setting, it will always pick the correct endian and no test is needed */ |
37 printf("#ifdef __BIG_ENDIAN__\n"); |
38 printf("#ifdef __BIG_ENDIAN__\n"); |
38 printf("#define TTD_BIG_ENDIAN\n"); |
39 printf("#define TTD_BIG_ENDIAN\n"); |
39 printf("#else\n"); |
40 printf("#else\n"); |
40 printf("#define TTD_LITTLE_ENDIAN\n"); |
41 printf("#define TTD_LITTLE_ENDIAN\n"); |
41 printf("#endif\n"); |
42 printf("#endif\n"); |