*** empty log message ***
[fw/sdcc] / support / regression / tests / funptrs.c
1 /** Function pointer tests.
2
3     type: char, int, long
4  */
5 #include <testfwk.h>
6
7 /* Must use a typedef as there is no way of adding the code modifier
8    on the z80.
9 */
10 typedef void (*NOARGFUNPTR)(void);
11 typedef void (*ONEARGFUNPTR)({type}) REENTRANT;
12
13 int count;
14
15 void
16 incCount(void)
17 {
18   count++;
19 }
20
21 void
22 incBy({type} a) REENTRANT
23 {
24   count += a;
25 }
26
27 void
28 callViaPtr(NOARGFUNPTR fptr)
29 {
30   (*fptr)();
31 }
32
33 void
34 callViaPtr2(ONEARGFUNPTR fptr, {type} arg)
35 {
36   (*fptr)(arg);
37 }
38
39 void
40 callViaPtr3(void (*fptr)(void))
41 {
42   (*fptr)();
43 }
44
45 void
46 testFunPtr(void)
47 {
48   ASSERT(count == 0);
49   callViaPtr(incCount);
50   ASSERT(count == 1);
51   callViaPtr2(incBy, 7);
52   ASSERT(count == 8);
53 }