1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-18 00:07:21 +00:00
cc65/test/val/ptrfunc.c

128 lines
2.1 KiB
C
Raw Normal View History

2014-09-24 14:45:10 +00:00
/*
!!DESCRIPTION!!
!!ORIGIN!! SDCC regression tests
!!LICENCE!! GPL, read COPYING.GPL
*/
#include <stdio.h>
2020-07-21 22:21:23 +00:00
/* #define SUPPORT_BIT_TYPES */
2014-09-24 14:45:10 +00:00
unsigned char success=0;
unsigned char failures=0;
unsigned char dummy=0;
#ifdef SUPPORT_BIT_TYPES
bit bit0 = 0;
#endif
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++"
*/
#if 0
unsigned char uchar0 = 0;
unsigned char uchar1 = 0;
unsigned char uchar2 = 0;
#else
volatile unsigned char uchar0 = 0;
volatile unsigned char uchar1 = 0;
volatile unsigned char uchar2 = 0;
#endif
void (*pfunc)(void);
void (*p1func)(void);
unsigned char (*pcfunc)(void);
void done()
{
dummy++;
}
void call0(void)
{
2019-02-12 21:50:49 +00:00
uchar0++;
2014-09-24 14:45:10 +00:00
}
void call1(void)
{
2019-02-12 21:50:49 +00:00
uchar1++;
2014-09-24 14:45:10 +00:00
}
unsigned char call2(void)
{
2019-02-12 21:50:49 +00:00
return uchar0 + 9;
2014-09-24 14:45:10 +00:00
}
void docall0(void)
{
2019-02-12 21:50:49 +00:00
pfunc = call0;
(pfunc)();
if(uchar0 != 1)
failures++;
2014-09-24 14:45:10 +00:00
}
void docall1()
{
2019-02-12 21:50:49 +00:00
unsigned char i;
for(i = 0; i < 3; i++) {
(*p1func)();
}
2014-09-24 14:45:10 +00:00
}
void docall2( void(*pf)() )
{
2019-02-12 21:50:49 +00:00
unsigned char i;
for(i = 0; i < 2; i++) {
pf();
}
2014-09-24 14:45:10 +00:00
}
int main(void)
{
docall0();
2019-02-12 21:50:49 +00:00
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)();
uchar2 += pcfunc();
success = failures;
done();
printf("failures: %d\n",failures);
return failures;
2014-09-24 14:45:10 +00:00
}