1#include <stdio.h>
2#include <string.h>
3
4static int w[2];
5static char * bytes;
6
7int main(void)
8{
9  printf ("+++Endian test:\n");
10  if (sizeof (int) == 2)
11    {
12      w[0] = 0x4142;
13      w[1] = 0;
14      bytes = (char *) w;
15      if (strcmp(bytes, "AB") == 0)
16	printf ("big endian\n");
17      else if (strcmp(bytes, "BA") == 0)
18	printf ("little endian\n");
19      else
20	{
21	  printf ("nor big nor little endian\n");
22	  return 1;
23	}
24    }
25  else if (sizeof (int) == 4)
26    {
27      w[0] = 0x41424344;
28      w[1] = 0;
29      bytes = (char *) w;
30      if (strcmp(bytes, "ABCD") == 0)
31	printf ("big endian\n");
32      else if (strcmp(bytes, "DCBA") == 0)
33	printf ("little endian\n");
34      else
35	{
36	  printf ("nor big nor little endian\n");
37	  return 1;
38	}
39    }
40  else
41    {
42      printf ("unexpected size of int\n");
43      return 1;
44    }
45  return 0;
46}
47