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(" %d", (int)((unsigned long) p1 - (unsigned long) p2));
36 main(int argc, char** argv)
38 unsigned long diff1, diff2, diff3, diff4;
40 printf("sizeof(struct Test) = %d\n\n", (int)sizeof(struct test));
42 printdiff(&TestArray[3], TestArray);
43 printdiff(&Test1.S.Y, &Test1.A);
44 printdiff(&Test1.next, &Test1.S.Y);
47 diff1 = (unsigned long) &TestArray[3] - (unsigned long) TestArray;
48 diff3 = (unsigned long) &Test1.S.Y - (unsigned long) &Test1.A;
49 diff4 = (unsigned long) &Test1.next - (unsigned long) &Test1.S.Y;
51 printf("&TestArray[3] - TestArray = 0x%lx\n", diff1);
52 printf("Xptr - Aptr = 0x%lx\n", diff3);
53 printf("NextPtr - Xptr = 0x%lx\n\n", diff4);
55 diff1 = (unsigned long) TestArrayPtr - (unsigned long) TestArray;
56 diff3 = (unsigned long) Yptr - (unsigned long) Aptr;
57 diff4 = (unsigned long) NextPtr - (unsigned long) Yptr;
59 printf("&TestArray[3] - TestArray = 0x%lx\n", diff1);
60 printf("Xptr - Aptr = 0x%lx\n", diff3);
61 printf("NextPtr - Xptr = 0x%lx\n\n", diff4);