byte_order.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* $Header$ */
  2. /*
  3. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. * See the copyright notice in the ACK home directory, in the file "Copyright".
  5. */
  6. #include <stdio.h>
  7. char bytes_reversed = 0;
  8. char words_reversed = 0;
  9. char char_unsigned = 0;
  10. /*
  11. * Determine the byte/word order in shorts/longs, assuming the size of a short
  12. * is 2 chars, and the size of a long is 4 chars. Not all theoretical
  13. * possibilities are tested; only bytes reversed and/or words reversed.
  14. */
  15. determine_ordering()
  16. {
  17. short s;
  18. long l;
  19. register char *cp;
  20. register short *sp;
  21. cp = (char *)&s;
  22. cp[0] = 0x01; cp[1] = 0x02;
  23. if (s != 0x01 + (0x02 << 8))
  24. bytes_reversed = 1;
  25. sp = (short *)&l;
  26. sp[0] = 0x0001; sp[1] = 0x0002;
  27. if (l != 0x0001 + (0x0002L << 16))
  28. words_reversed = 1;
  29. }
  30. /*
  31. * determine whether characters are unsigned or signed
  32. */
  33. uns_char()
  34. {
  35. char c = 0200;
  36. int i = c;
  37. if (i > 0) char_unsigned = 1;
  38. }
  39. main()
  40. {
  41. determine_ordering();
  42. uns_char();
  43. printf("#define BYTES_REVERSED %d\n", bytes_reversed);
  44. printf("#define WORDS_REVERSED %d\n", words_reversed);
  45. printf("#define CHAR_UNSIGNED %d\n", char_unsigned);
  46. return 0;
  47. }