1 /** Function pointer tests.
3 type: bool, char, int, long
15 /* Must use a typedef as there is no way of adding the code modifier
18 typedef void (*NOARGFUNPTR
)(void);
19 typedef void (*ONEARGFUNPTR
)({type
}) __reentrant
;
20 typedef long int (*FOURARGFUNPTR
)(char, char, long int, long int) __reentrant
;
21 typedef {type
} (*TYPEFUNPTR
)({type
}, {type
}) __reentrant
;
34 incBy({type
} a
) __reentrant
39 long int f6(char a
, char b
, long int c
, long int d
) __reentrant
53 callViaPtr(NOARGFUNPTR fptr
)
59 callViaPtr2(ONEARGFUNPTR fptr
, {type
} arg
)
65 callViaPtr3(void (*fptr
)(void))
71 callViaPtrAnsi(NOARGFUNPTR fptr
)
77 callViaPtr2Ansi(ONEARGFUNPTR fptr
, {type
} arg
)
83 callViaPtr3Ansi(void (*fptr
)(void))
88 {type
} f_ret({type
} arg1
, {type
} arg2
) __reentrant
92 return (local
& arg2
);
99 #if !defined(__SDCC_pdk14) // Lack of memory
103 callViaPtr(incCount
);
105 callViaPtr2(incBy
, 7);
106 ASSERT(count
== 8 || count
== 2);
108 ASSERT((*fafp
)(0, 0x55, 0x12345678, 0x9abcdef0) == 0);
109 ASSERT((*fafp
)(1, 0x55, 0x12345678, 0x9abcdef0) == 0x55);
110 ASSERT((*fafp
)(2, 0x55, 0x12345678, 0x9abcdef0) == 0x12345678);
111 ASSERT((*fafp
)(3, 0x55, 0x12345678, 0x9abcdef0) == 0x9abcdef0);
118 #if !defined(__SDCC_pdk14) // Lack of memory
122 callViaPtrAnsi(incCount
);
124 callViaPtr2Ansi(incBy
, 7);
125 ASSERT(count
== 8 || count
== 2);
127 ASSERT(fafp(0, 0x55, 0x12345678, 0x9abcdef0) == 0);
128 ASSERT(fafp(1, 0x55, 0x12345678, 0x9abcdef0) == 0x55);
129 ASSERT(fafp(2, 0x55, 0x12345678, 0x9abcdef0) == 0x12345678);
130 ASSERT(fafp(3, 0x55, 0x12345678, 0x9abcdef0) == 0x9abcdef0);
135 testFunPtrReturn(void)
137 #if !defined(__SDCC_pdk14) // Lack of memory
138 #if !(defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
141 ASSERT(tfp(0, 0) == 0);
142 ASSERT(tfp(0, 1) == 1);
143 ASSERT(tfp(1, 0) == 0);
144 ASSERT(tfp(1, 1) == 0);