File: nestfor.c

package info (click to toggle)
cc65 2.19-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,268 kB
  • sloc: ansic: 117,151; asm: 66,339; pascal: 4,248; makefile: 1,009; perl: 607
file content (151 lines) | stat: -rw-r--r-- 3,040 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
  !!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)
{
        /*PORTB = val;
        PORTA = 0x01;
        PORTA = 0x00;
        */
}

void done()
{
  dummy++;
}

/* both loops use the loop variable inside the inner loop */
void for1(void)
{
        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++;
}

/* only the outer loop's variable is used inside, inner can be optimized into a repeat-loop */
void for2(void)
{
        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++;
}

/* only the inner loop's variable is used inside */
void for3(void)
{
        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++;
}

/* neither loop variable used inside the loops */
void for4(void)
{
        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++;
}

/* like for1 but different condition in inner loop */
void for5(void)
{
        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++;
}

int  main(void)
{
  for1();
  for2();
  for3();
  for4();
  for5();

  success = failures;
  done();
  printf("failures: %d\n",failures);

  return failures;
}