endian_check.cpp

Go to the documentation of this file.
00001 /* $Id: endian_check.cpp 10684 2007-07-25 00:16:30Z rubidium $ */
00002 
00012 #include <stdio.h>
00013 #include <string.h>
00014 
00021 int main (int argc, char *argv[])
00022 {
00023   unsigned char endian_test[2] = { 1, 0 };
00024   int force_BE = 0, force_LE = 0, force_PREPROCESSOR = 0;
00025 
00026   if (argc > 1 && strcmp(argv[1], "BE") == 0) force_BE = 1;
00027   if (argc > 1 && strcmp(argv[1], "LE") == 0) force_LE = 1;
00028   if (argc > 1 && strcmp(argv[1], "PREPROCESSOR") == 0) force_PREPROCESSOR = 1;
00029 
00030   printf("#ifndef ENDIAN_H\n#define ENDIAN_H\n");
00031 
00032   if (force_LE == 1) {
00033     printf("#define TTD_LITTLE_ENDIAN\n");
00034   } else if (force_BE == 1) {
00035     printf("#define TTD_BIG_ENDIAN\n");
00036   } else if (force_PREPROCESSOR == 1) {
00037     /* Support for universal binaries on OSX
00038      * Universal binaries supports both PPC and x86
00039      * If a compiler for OSX gets this setting, it will always pick the correct endian and no test is needed
00040      */
00041     printf("#ifdef __BIG_ENDIAN__\n");
00042     printf("#define TTD_BIG_ENDIAN\n");
00043     printf("#else\n");
00044     printf("#define TTD_LITTLE_ENDIAN\n");
00045     printf("#endif\n");
00046   } else if (*(short*)endian_test == 1 ) {
00047     printf("#define TTD_LITTLE_ENDIAN\n");
00048   } else {
00049     printf("#define TTD_BIG_ENDIAN\n");
00050   }
00051   printf("#endif\n");
00052 
00053   return 0;
00054 }

Generated on Wed Oct 1 17:03:20 2008 for openttd by  doxygen 1.5.6