The following program decides the byte order of a given computer by verifying th
ID: 3633731 • Letter: T
Question
The following program decides the byte order of a given computer by verifying the byte order of a short integer. Modify that program so that it will decide the byte order of a computer by checking the byte order of a long integer on department Linux workstations. Run your program on at least two Linux workstations to see their byte orders.1 #include "unp.h"
2 int
3 main(int argc, char **argv)
4 {
5 union {
6 short s;
7 char c[sizeof(short)];
8 } un;
9 un.s = 0x0102;
10 printf("%s: ", CPU_VENDOR_OS);
11 if (sizeof(short) == 2) {
12 if (un.c[0] == 1 && un.c[1] == 2)
13 printf("big-endian ");
14 else if (un.c[0] == 2 && un.c[1] == 1)
15 printf("little-endian ");
16 else
17 printf("unknown ");
18 } else
19 printf("sizeof(short) = %d ", sizeof(short));
20 exit(0);
21 }