2 ** !!DESCRIPTION!! Simple tests of pointer-to-array dereferences
3 ** !!ORIGIN!! cc65 regression tests
4 ** !!LICENCE!! Public Domain
5 ** !!AUTHOR!! 2015-06-29, Greg King
10 static unsigned char failures = 0;
13 typedef unsigned char array_t[4][4];
15 static array_t table = {
21 static array_t *tablePtr = &table;
23 static unsigned (*vector)[2];
25 static unsigned char y = 0, x;
29 /* The indirection must convert the expression-type (from Pointer into
30 ** Array); but, it must not convert the value, because it already points
31 ** to the start of the array.
33 /* (Note: I reduce output clutter by using a variable to prevent
34 ** compiler warnings about constant comparisons and unreachable code.
36 if ((Size = sizeof *tablePtr) != sizeof table) {
39 if (*tablePtr != table) {
47 if ((*tablePtr)[y][x] != table[y][x]) {
49 printf("(*tableptr)[%u][%u] (%u) != table[%u][%u] (%u).\n",
50 y, x, (*tablePtr)[y][x],
53 } while (++x < sizeof table[0]);
54 } while (++y < sizeof table / sizeof table[0]);
56 vector = (unsigned (*)[])table[1];
57 if ((*vector)[1] != 0x0B0A) {
62 (*tablePtr)[2][1] = 42;
63 if (table[2][1] != 42) {
65 printf("table[2][1] == %u (should have changed from 5 to 42).\n",
70 (*tablePtr)[y][x] = 83;
71 if (table[1][3] != 83) {
73 printf("table[y][x] == %u (should have changed from 11 to 83).\n",
77 /* Test triple indirection. It should compile to two indirection
83 printf("**table == %u (should have changed from 12 to 11).\n",
88 printf("failures: %u\n", failures);