Steve Tell wrote this test program to test function pointers (note that
authorsdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 11 Apr 2003 00:33:07 +0000 (00:33 +0000)
committersdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 11 Apr 2003 00:33:07 +0000 (00:33 +0000)
this code still does not successfully pass the regression test).

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2502 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/regression/ptrfunc.c [new file with mode: 0644]

diff --git a/src/regression/ptrfunc.c b/src/regression/ptrfunc.c
new file mode 100644 (file)
index 0000000..edab837
--- /dev/null
@@ -0,0 +1,112 @@
+#define __16F873
+#include "p16f873.h"
+//#include "p16c84.h"
+
+unsigned char success=0;
+unsigned char failures=0;
+unsigned char dummy=0;
+
+bit bit0 = 0;
+unsigned int uint0 = 0;
+unsigned int uint1 = 0;
+
+/* 
+ * BUG: if these aren't volatile, an overzealous optimizer or somthing
+ * wreaks havoc with the simple tests like "if(uchar != 3)failures++"
+ */
+volatile unsigned char uchar0 = 0;
+volatile unsigned char uchar1 = 0;
+volatile unsigned char uchar2 = 0;
+
+void (*pfunc)();
+void (*p1func)();
+unsigned char (*pcfunc)();
+
+void done()
+{
+
+  dummy++;
+
+}
+
+void call0(void)
+{
+       uchar0++;
+}
+
+void call1(void)
+{
+       uchar1++;
+}
+
+unsigned char call2(void)
+{
+       return uchar0 + 9;
+}
+
+void docall0(void)
+{
+       pfunc = call0;
+       (pfunc)();
+       if(uchar0 != 1)
+               failures++;
+}
+
+void docall1()
+{
+       unsigned char i;
+       for(i = 0; i < 3; i++) {
+               (*p1func)();
+       }
+}
+
+void docall2( void(*pf)() )
+{
+       unsigned char i;
+       for(i = 0; i < 2; i++) {
+               pf();
+       }
+}
+
+void main(void)
+{
+       docall0();
+
+
+       p1func = call1;
+       docall1();
+       if(uchar1 != 3)
+               failures++;
+       if(uchar0 != 1)
+               failures++;
+
+       p1func = call0;
+       docall1();
+       if(uchar1 != 3)
+               failures++;
+       if(uchar0 != 4)
+               failures++;
+
+       docall2(call0);
+       if(uchar1 != 3)
+               failures++;
+       if(uchar0 != 6)
+               failures++;
+
+       docall2(call1);
+       if(uchar1 != 5)
+               failures++;
+       if(uchar0 != 6)
+               failures++;
+
+       pcfunc = call2;
+       uchar2 = (*pcfunc)();
+       if(uchar2 != 15)
+               failures++;
+/**/
+/*     uchar2 += (pcfunc)(); */ /* FRONT-END BUG? - type-mismatch error */
+/*     uchar2 += pcfunc(); */ /* FRONT-END BUG? - type-mismatch error */
+
+       success = failures;
+       done();
+}