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