1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-03 10:07:02 +00:00
cc65/test/val/for-nested.c

152 lines
3.0 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>
#include <limits.h>
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;
unsigned char uchar0 = 0;
unsigned char uchar1 = 0;
void dput(unsigned char val)
{
2019-02-12 21:50:49 +00:00
/*PORTB = val;
PORTA = 0x01;
PORTA = 0x00;
*/
2014-09-24 14:45:10 +00:00
}
void done()
{
dummy++;
}
/* both loops use the loop variable inside the inner loop */
void for1(void)
{
2019-02-12 21:50:49 +00:00
unsigned char i, j;
uchar0 = 0;
uchar1 = 0;
for(i = 0; i < 3; i++) {
uchar0++;
for(j = 0; j < 4; j++) {
uchar1++;
dput(i);
dput(j);
}
}
if(uchar0 != 3)
failures++;
if(uchar1 != 12)
failures++;
2014-09-24 14:45:10 +00:00
}
/* only the outer loop's variable is used inside, inner can be optimized into a repeat-loop */
void for2(void)
{
2019-02-12 21:50:49 +00:00
unsigned char i, j;
uchar0 = 0;
uchar1 = 0;
for(i = 0; i < 3; i++) {
uchar0++;
for(j = 0; j < 4; j++) {
uchar1++;
dput(i);
}
}
if(uchar0 != 3)
failures++;
if(uchar1 != 12)
failures++;
2014-09-24 14:45:10 +00:00
}
/* only the inner loop's variable is used inside */
void for3(void)
{
2019-02-12 21:50:49 +00:00
unsigned char i, j;
uchar0 = 0;
uchar1 = 0;
for(i = 0; i < 3; i++) {
uchar0++;
for(j = 0; j < 4; j++) {
uchar1++;
dput(j);
}
}
if(uchar0 != 3)
failures++;
if(uchar1 != 12)
failures++;
2014-09-24 14:45:10 +00:00
}
/* neither loop variable used inside the loops */
void for4(void)
{
2019-02-12 21:50:49 +00:00
unsigned char i, j;
uchar0 = 0;
uchar1 = 0;
for(i = 0; i < 3; i++) {
uchar0++;
for(j = 0; j < 4; j++) {
uchar1++;
dput(uchar0);
dput(uchar1);
}
}
if(uchar0 != 3)
failures++;
if(uchar1 != 12)
failures++;
2014-09-24 14:45:10 +00:00
}
/* like for1 but different condition in inner loop */
void for5(void)
{
2019-02-12 21:50:49 +00:00
unsigned char i, j;
uchar0 = 0;
uchar1 = 0;
for(i = 0; i < 3; i++) {
uchar0++;
for(j = 10; j >= 5; j--) {
uchar1++;
dput(i);
dput(j);
}
}
if(uchar0 != 3)
failures++;
if(uchar1 != 18)
failures++;
2014-09-24 14:45:10 +00:00
}
int main(void)
{
for1();
for2();
for3();
for4();
for5();
success = failures;
done();
printf("failures: %d\n",failures);
return failures;
}