]> git.sur5r.net Git - cc65/blob - test/val/and1.c
goto.c warning fix for implicit truncation
[cc65] / test / val / and1.c
1 /*
2   !!DESCRIPTION!!
3   !!ORIGIN!!      SDCC regression tests
4   !!LICENCE!!     GPL, read COPYING.GPL
5 */
6
7 #include <stdio.h>
8 #include <limits.h>
9
10 unsigned char success=0;
11 unsigned char failures=0;
12 unsigned char dummy=0;
13
14 unsigned int uint0 = 0;
15 unsigned int uint1 = 0;
16 unsigned char uchar0 = 0;
17 unsigned char uchar1 = 0;
18 unsigned long ulong0 = 0;
19
20 void done()
21 {
22   dummy++;
23 }
24
25 /* uchar0 = 0xff; */
26 void and_lit2uchar(void)
27 {
28   if(uchar0 != 0xff)
29     failures++;
30
31   uchar0 &= 0x7f;
32
33   if(uchar0 != 0x7f)
34     failures++;
35
36   uchar0 &= 0x3f;
37
38   if(uchar0 != 0x3f)
39     failures++;
40
41   uchar0 &= 0xdf;
42
43   if(uchar0 != 0x1f)
44     failures++;
45 }
46
47 void and_lit2uint(void)
48 {
49   if(uint0 != 0xffff)
50     failures++;
51
52   uint0 &= 0x7fff;
53
54   if(uint0 != 0x7fff)
55     failures++;
56
57   uint0 &= 0x3fff;
58
59   if(uint0 != 0x3fff)
60     failures++;
61
62   uint0 &= 0xdfff;
63
64   if(uint0 != 0x1fff)
65     failures++;
66
67   uint0 &= 0xff7f;
68
69   if(uint0 != 0x1f7f)
70     failures++;
71
72   uint0 &= 0x0f0f;
73
74   if(uint0 != 0x0f0f)
75     failures++;
76
77   uint0 &= 0xfefe;
78
79   if(uint0 != 0x0e0e)
80     failures++;
81
82   uint0 &= 0xf0f0;
83
84   if(uint0 != 0)
85     failures++;
86 }
87
88 void and_lit2ulong(void)
89 {
90   if(ulong0 != 0xffffffff)
91     failures++;
92
93   ulong0 &= 0x7fffffff;
94
95   if(ulong0 != 0x7fffffff)
96     failures++;
97
98   ulong0 &= 0xff00ffff;
99
100   if(ulong0 != 0x7f00ffff)
101     failures++;
102
103   ulong0 &= 0xfeff00ff;
104
105   if(ulong0 != 0x7e0000ff)
106     failures++;
107 }
108
109 /*-----------*/
110 void and_uchar2uchar(void)
111 {
112   uchar0 &= uchar1;
113
114   if(uchar0 != 0x0f)
115     failures++;
116
117   uchar1 &= 0xf7;
118
119   uchar0 = uchar1 & 0xfe;
120
121   if(uchar0 != 0x06)
122     failures++;
123 }
124
125 int main(void)
126 {
127   uchar0 = 0xff;
128   and_lit2uchar();
129
130   uint0 = 0xffff;
131   and_lit2uint();
132
133   ulong0 = 0xffffffff;
134   and_lit2ulong();
135
136   uchar0 = 0xff;
137   uchar1 = 0x0f;
138   and_uchar2uchar();
139
140   success = failures;
141   done();
142   printf("failures: %d\n",failures);
143
144   return failures;
145 }