Merge from mainline
[official-gcc.git] / gcc / testsuite / consistency.vlad / layout / endian.c
blobe172a1aaf1bc9cbfbd707c7bbd27b2f551a17c7b
1 #include <stdio.h>
2 #include <string.h>
4 static int w[2];
5 static char * bytes;
7 int main(void)
9 printf ("+++Endian test:\n");
10 if (sizeof (int) == 2)
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
21 printf ("nor big nor little endian\n");
22 return 1;
25 else if (sizeof (int) == 4)
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
36 printf ("nor big nor little endian\n");
37 return 1;
40 else
42 printf ("unexpected size of int\n");
43 return 1;
45 return 0;