From e0388273dc164ec1264d6e8229e42bc01cefa78c Mon Sep 17 00:00:00 2001 From: michaelh Date: Wed, 31 Oct 2001 03:45:15 +0000 Subject: [PATCH] Added. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1476 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- support/regression/tests/funptrs.c | 51 ++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 support/regression/tests/funptrs.c diff --git a/support/regression/tests/funptrs.c b/support/regression/tests/funptrs.c new file mode 100644 index 00000000..6288d94d --- /dev/null +++ b/support/regression/tests/funptrs.c @@ -0,0 +1,51 @@ +/** Function pointer tests. + */ +#include + +/* Must use a typedef as there is no way of adding the code modifier + on the z80. +*/ +typedef void (*NOARGFUNPTR)(void); +typedef void (*ONEARGFUNPTR)(int); + +int count; + +void +incCount(void) +{ + count++; +} + +void +incBy(int a) +{ + count += a; +} + +void +callViaPtr(NOARGFUNPTR fptr) +{ + (*fptr)(); +} + +void +callViaPtr2(ONEARGFUNPTR fptr, int arg) +{ + (*fptr)(arg); +} + +void +callViaPtr3(void (*fptr)(void)) +{ + (*fptr)(); +} + +void +testFunPtr(void) +{ + ASSERT(count == 0); + callViaPtr(incCount); + ASSERT(count == 1); + callViaPtr2(incBy, 7); + ASSERT(count == 8); +} -- 2.30.2