endian_check.c
author hackykid
Sun, 22 May 2005 14:10:20 +0000
changeset 1855 caf6d1396112
parent 1692 2587eee1c632
child 2186 461a2aff3486
permissions -rw-r--r--
(svn r2361) - Feature: [newgrf] Implement varaction2 property 0x41 and 0xDA. These are the position in and length of chain of consecutive vehicles with the same type, and index of the next wagon in the chain (INVALID_VEHICLE if last), resp. Improves displaying of some engines in the dbsetxl.
157
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
     1
#include <stdio.h>
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
     2
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
     3
// This pretty simple file checks if the system is LITTLE_ENDIAN or BIG_ENDIAN
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
     4
//  it does that by putting a 1 and a 0 in an array, and read it out as one
200
03b8104d1479 (svn r201) -Fix: [1025836] Company values bigger dan int32 were put to negative
truelight
parents: 157
diff changeset
     5
//  number. If it is 1, it is LITTLE_ENDIAN, if it is 256, it is BIG_ENDIAN
157
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
     6
//
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
     7
// After that it outputs the contents of an include files (endian.h)
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
     8
//  that says or TTD_LITTLE_ENDIAN, or TTD_BIG_ENDIAN. Makefile takes
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
     9
//  care of the real writing to the file.
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    10
1692
2587eee1c632 (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    11
int main (int argc, char *argv[]) {
157
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    12
  unsigned char EndianTest[2] = { 1, 0 };
1692
2587eee1c632 (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    13
  int force_BE = 0, force_LE = 0;
2587eee1c632 (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    14
2587eee1c632 (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    15
  if (argc > 1 && strcmp(argv[1], "BE") == 0)
2587eee1c632 (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    16
    force_BE = 1;
2587eee1c632 (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    17
  if (argc > 1 && strcmp(argv[1], "LE") == 0)
2587eee1c632 (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    18
    force_LE = 1;
2587eee1c632 (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    19
157
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    20
  printf("#ifndef ENDIAN_H\n#define ENDIAN_H\n");
1692
2587eee1c632 (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    21
2587eee1c632 (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    22
  if ( (*(short *) EndianTest == 1 && force_BE != 1) || force_LE == 1)
157
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    23
    printf("#define TTD_LITTLE_ENDIAN\n");
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    24
  else
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    25
    printf("#define TTD_BIG_ENDIAN\n");
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    26
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    27
  printf("#endif\n");
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    28
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    29
  return 0;
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    30
}