1 extern int ival;
2 extern int *ipval;
3 extern int array[3];
4 extern int matrix[3][3];
5 extern int fun(int);
6
7 // via an argument
8 void arg(int a, int *p, int (*fb)(unsigned char), int (*fi)(int), int (*fl)(long), int (*fv)(void), int (*fip)(int *), int (*fim)(int (*)[3]), int (*fvp)(void *), int (*ffp)(int (*)(int)));
arg(int a,int * p,int (* fb)(unsigned char),int (* fi)(int),int (* fl)(long),int (* fv)(void),int (* fip)(int *),int (* fim)(int (*)[3]),int (* fvp)(void *),int (* ffp)(int (*)(int)))9 void arg(int a, int *p, int (*fb)(unsigned char), int (*fi)(int), int (*fl)(long), int (*fv)(void), int (*fip)(int *), int (*fim)(int (*)[3]), int (*fvp)(void *), int (*ffp)(int (*)(int)))
10 {
11 fv();
12
13 fb(a);
14 fi(a);
15 fl(a);
16 fb(123);
17 fi(123);
18 fl(123);
19 fb(123L);
20 fi(123L);
21 fl(123L);
22 fb(ival);
23 fi(ival);
24 fl(ival);
25
26 fip(p);
27 fip((void*)0);
28 fip(ipval);
29 fip(&ival);
30 fip(array);
31 fim(matrix);
32
33 fvp(p);
34 fvp((void*)0);
35 fvp(ipval);
36 fvp(&ival);
37 fvp(array);
38 fvp(matrix);
39
40 fvp(fun);
41 fvp(&fun);
42 ffp(fun);
43 ffp(&fun);
44 }
45
46 // a global
47 extern int (*fb)(unsigned char);
48 extern int (*fi)(int);
49 extern int (*fl)(long);
50 extern int (*fv)(void);
51 extern int (*fip)(int *);
52 extern int (*fim)(int (*)[3]);
53 extern int (*fvp)(void *);
54 extern int (*ffp)(int (*)(int));
55
56 void glb(int a, int *p);
glb(int a,int * p)57 void glb(int a, int *p)
58 {
59 fv();
60
61 fb(a);
62 fi(a);
63 fl(a);
64 fb(123);
65 fi(123);
66 fl(123);
67 fb(123L);
68 fi(123L);
69 fl(123L);
70 fb(ival);
71 fi(ival);
72 fl(ival);
73
74 fip(p);
75 fip((void*)0);
76 fip(ipval);
77 fip(&ival);
78 fip(array);
79 fim(matrix);
80
81 fvp(p);
82 fvp((void*)0);
83 fvp(ipval);
84 fvp(&ival);
85 fvp(array);
86 fvp(matrix);
87
88 fvp(fun);
89 fvp(&fun);
90 ffp(fun);
91 ffp(&fun);
92 }
93
94 // via a struct member:
95 // -> force to create a register containing the function pointer
96 struct ops {
97 int (*fb)(unsigned char);
98 int (*fi)(int);
99 int (*fl)(long);
100 int (*fv)(void);
101 int (*fip)(int *);
102 int (*fim)(int (*)[3]);
103 int (*fvp)(void *);
104 int (*ffp)(int (*)(int));
105
106 int (*const cfi)(int); // for the fun of it
107 };
108
109 void ops(int a, int *p, struct ops *ops);
ops(int a,int * p,struct ops * ops)110 void ops(int a, int *p, struct ops *ops)
111 {
112 ops->fv();
113
114 ops->fb(a);
115 ops->fi(a);
116 ops->fl(a);
117 ops->fb(123);
118 ops->fi(123);
119 ops->fl(123);
120 ops->fb(123L);
121 ops->fi(123L);
122 ops->fl(123L);
123 ops->fb(ival);
124 ops->fi(ival);
125 ops->fl(ival);
126
127 ops->fip(p);
128 ops->fip((void*)0);
129 ops->fip(ipval);
130 ops->fip(&ival);
131 ops->fip(array);
132 ops->fim(matrix);
133
134 ops->fvp(p);
135 ops->fvp((void*)0);
136 ops->fvp(ipval);
137 ops->fvp(&ival);
138 ops->fvp(array);
139 ops->fvp(matrix);
140
141 ops->fvp(fun);
142 ops->fvp(&fun);
143 ops->ffp(fun);
144 ops->ffp(&fun);
145 ops->fvp(fi);
146
147 ops->cfi(42);
148 }
149
150 /*
151 * check-name: Function pointer code generation
152 * check-command: sparsec -c $file -o tmp.o
153 */
154