home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.pdx.edu / 2014.02.ftp.ee.pdx.edu.tar / ftp.ee.pdx.edu / pub / users / Harry / Blitz / version-1-0 / Beta / endian.c < prev    next >
C/C++ Source or Header  |  2007-09-04  |  1KB  |  40 lines

  1. /* endian - A program to check the host machine's byte order
  2. **
  3. ** Harry Porter
  4. **
  5. ** Run this program if you have any questions about whether you are
  6. ** compiling and running on a big- or little-endian machine.
  7. **
  8. ** NOTE: Some machines can execute in both modes.  For example, the new Macs
  9. ** which contain Intel processors (e.g., MacPro, MacBookPro, ...) can compile
  10. ** and execute legacy code for the older G4/G5/PowerPC processors.  Therefore the
  11. ** output of this little program will only tell you about the environment in which
  12. ** programs are executed.
  13. */
  14.  
  15. #include <stdio.h>
  16. #include <strings.h>
  17.  
  18. int i;
  19. char * p;
  20.  
  21. main () {
  22.   printf ("*******************************\nThis program tests whether it is running on an architecture with Big Endian or Little Endian byte ordering...\n");
  23.   i = 0x12345678;
  24.   printf ("The following line should print 0x12345678...\n");
  25.   printf ("        0x%08x\n", i);
  26.   printf ("This program stores 11, 22, 33, and 44 in sucessive bytes and then accesses it as a 4 byte integer.\n");
  27.   p = (char *) (& i);
  28.   *p = 0x11;
  29.   p++;
  30.   *p = 0x22;
  31.   p++;
  32.   *p = 0x33;
  33.   p++;
  34.   *p = 0x44;
  35.   printf ("Big Endian machines will print 0x11223344 next, while\n");
  36.   printf ("Little Endian machines will print 0x44332211 next...\n");
  37.   printf ("        0x%08x\n", i);
  38.   printf ("*******************************\n");
  39. }
  40.