]> git.sur5r.net Git - cc65/blob - test/ref/pointer2.c
remote TABs in doc/ and test/
[cc65] / test / ref / pointer2.c
1 /*
2   !!DESCRIPTION!! pointer test
3   !!ORIGIN!!
4   !!LICENCE!!     public domain
5 */
6
7 #include "common.h"
8 #include <stdio.h>
9
10 /*
11   check behaviour on incompletely declared arrays
12 */
13
14 char i1[];
15
16 void test1(void) {
17 int a;
18
19         a=sizeof(i1[0]);
20         printf("%04x - ",a);
21         if(sizeof(i1[0])==sizeof(char)) {
22                 /* gcc gives size of element */
23                 printf("sizeof(i1[0]) gives size of element\n");
24         }
25         if(sizeof(i1[0])==sizeof(char*)) {
26                 printf("sizeof(i1[0]) gives size of pointer to element\n");
27         }
28 }
29
30 /*
31   check behaviour on string init
32 */
33
34 char t1[]="abcde";
35 char t2[]={"abcde"};
36
37 char *t3="abcde";
38 char *t4={"abcde"};
39
40 void test2(void) {
41 char c1,c2,c3,c4;
42 int i,e=0;
43         for(i=0;i<5;i++){
44                 c1=t1[i];c2=t2[i];c3=t3[i];c4=t4[i];
45 /*              printf("%02x %02x %02x %02x\n",c1,c2,c3,c4); */
46                 printf("%c %c %c %c\n",c1,c2,c3,c4);
47                 if(!((c1==c2)&(c1==c3)&(c1==c4))) e=1;
48         }
49         if(e) printf("test2 failed.\n");
50         else printf("test2 ok.\n");
51 }
52
53 /*
54   check behaviour on extern-declarations inside functions
55 */
56
57 typedef struct {
58   char *name;
59   void *func;
60 } A3;
61
62 #ifdef NO_SLOPPY_STRUCT_INIT
63 A3 a3[] = {
64   { "test3", (void*) NULL },
65   { "test3", (void*) NULL },
66 };
67 #else
68 /*gcc warning: missing braces around initializer (near initialization for `a3[0]')
69   this type of struct-initialization seems to be kinda common */
70 A3 a3[] = {
71     "test3", (void*) NULL  ,
72     "test3", (void*) NULL  ,
73 };
74 #endif
75
76 void test3a(A3 *list, int number){
77         printf("%s %d\n",list->name,number);
78 }
79
80 static void test31(void)
81 {
82     extern A3 a3[];
83     test3a(a3, -1);
84 }
85
86 #if 0
87 /* this variation compiles and works with cc65, but gives an error with gcc :=P */
88 static void test32(void)
89 {
90     extern A3 *a3;
91     test3a(a3, -1);
92 }
93 #endif
94
95 static void test30(void)
96 {
97     test3a(a3, -1);
98 }
99
100 /*
101   todo: add test on function pointers in the form of (*func)(arg) ...
102   cc65 seems to have problems here aswell ;/
103 */
104
105 int main(void) {
106         test1();
107         test2();
108         test30();
109         test31();
110 /*      test32(); */
111         return 0;
112 }