1 /* globalrefs.c - Test symbolic constant expressions constructed from
2 * global addresses and index expressions into global addresses.
3 * Do this both with global constants and with inline constant.
4 * Instead of printing absolute addresses, print out the differences in
5 * memory addresses to get output that matches that of the native compiler.
10 #define __STDC_LIMIT_MACROS 1
15 struct { unsigned X; unsigned Y; } S;
19 struct test TestArray[10];
22 /* Create global symbolic constants from the addresses of the above globals */
24 struct test* TestArrayPtr = &TestArray[3];
25 long* Aptr = &Test1.A;
26 unsigned* Yptr = &Test1.S.Y;
27 struct test** NextPtr = &Test1.next;
30 printdiff(void* p1, void* p2)
32 printf(" 0x%lx", (unsigned long) p1 - (unsigned long) p2);
36 main(int argc, char** argv)
38 unsigned long diff1, diff2, diff3, diff4;
40 printf("sizeof(struct Test) = %llu\n\n", sizeof(struct test));
42 printdiff(&TestArray[3], TestArray);
43 printdiff(&Test1.A, &TestArray[3]);
44 printdiff(&Test1.S.Y, &Test1.A);
45 printdiff(&Test1.next, &Test1.S.Y);
48 diff1 = (unsigned long) &TestArray[3] - (unsigned long) TestArray;
49 diff2 = (unsigned long) &Test1.A - (unsigned long) &TestArray[3];
50 diff3 = (unsigned long) &Test1.S.Y - (unsigned long) &Test1.A;
51 diff4 = (unsigned long) &Test1.next - (unsigned long) &Test1.S.Y;
53 printf("&TestArray[3] - TestArray = 0x%lx\n", diff1);
54 printf("Aptr - &TestArray[3] = 0x%lx\n", diff2);
55 printf("Xptr - Aptr = 0x%lx\n", diff3);
56 printf("NextPtr - Xptr = 0x%lx\n\n", diff4);
58 diff1 = (unsigned long) TestArrayPtr - (unsigned long) TestArray;
59 diff2 = (unsigned long) Aptr - (unsigned long) TestArrayPtr;
60 diff3 = (unsigned long) Yptr - (unsigned long) Aptr;
61 diff4 = (unsigned long) NextPtr - (unsigned long) Yptr;
63 printf("&TestArray[3] - TestArray = 0x%lx\n", diff1);
64 printf("Aptr - &TestArray[3] = 0x%lx\n", diff2);
65 printf("Xptr - Aptr = 0x%lx\n", diff3);
66 printf("NextPtr - Xptr = 0x%lx\n\n", diff4);