home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / disk / archive / nspark_1 / nspark-1.7.5 / mkendian.c < prev    next >
C/C++ Source or Header  |  1995-01-06  |  1KB  |  58 lines

  1. /*
  2.  * Determine byte-sex of local host to enable RISC OS (little endian) files
  3.  * to be read/written.
  4.  *
  5.  * $Header: mkendian.c 1.3 95/01/06 $
  6.  * $Log:    mkendian.c,v $
  7.  * Revision 1.3  95/01/06  12:02:00  arb
  8.  * Fixes for Alpha.
  9.  *
  10.  * Revision 1.2  92/12/07  17:19:05  duplain
  11.  * reformatted source.
  12.  * 
  13.  * Revision 1.1  92/09/29  18:02:23  duplain
  14.  * Initial revision
  15.  * 
  16.  */
  17.  
  18. #include <stdio.h>
  19.  
  20. void
  21. main()
  22. {
  23.     register i;
  24.     union {
  25. #ifdef __alpha
  26.     unsigned int l;
  27. #else
  28.     unsigned long l;
  29. #endif
  30.     unsigned short w;
  31.     char c[4];
  32.     } x;
  33.  
  34.     if (sizeof(x.l) != 4 || sizeof(x.w) != 2) {
  35.     fprintf(stderr, "size mismatch in union... aborting\n");
  36.     exit(1);
  37.     }
  38.  
  39.     puts("/* endian.h:  local host specific byte-sex defines */");
  40.     puts("#ifndef __ENDIAN_H");
  41.     puts("#define __ENDIAN_H");
  42.  
  43.     x.l = 0x00010203;
  44.     if (x.c[0] == 3 && x.c[1] == 2 && x.c[2] == 1 && x.c[3] == 0)
  45.     puts("#define LITTLE_ENDIAN");
  46.     else
  47.     puts("#undef LITTLE_ENDIAN");
  48.     for (i = 0; i < 4; i++)
  49.     printf("#define WORD%d\t%d\n", i, 3 - x.c[i]);
  50.  
  51.     x.w = 0x0001;
  52.     for (i = 0; i < 2; i++)
  53.     printf("#define HALFWORD%d\t%d\n", i, 1 - x.c[i]);
  54.  
  55.     puts("#endif /* __ENDIAN_H */");
  56.     exit(0);
  57. }
  58.