Added.
authormichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 31 Oct 2001 03:45:15 +0000 (03:45 +0000)
committermichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 31 Oct 2001 03:45:15 +0000 (03:45 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1476 4a8a32a2-be11-0410-ad9d-d568d2c75423

support/regression/tests/funptrs.c [new file with mode: 0644]

diff --git a/support/regression/tests/funptrs.c b/support/regression/tests/funptrs.c
new file mode 100644 (file)
index 0000000..6288d94
--- /dev/null
@@ -0,0 +1,51 @@
+/** Function pointer tests.
+ */
+#include <testfwk.h>
+
+/* 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);
+}