Skip to content
This repository was archived by the owner on Nov 22, 2023. It is now read-only.

Commit c8aa9cc

Browse files
committed
add struct assign check related to cc65#2079
1 parent 31bac03 commit c8aa9cc

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

test/val/bug2079-struct-assign.c

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
2+
/* test struct assignment, of structs with a length of 3, which happen to be
3+
a special case eg when passing/returning structs
4+
related to bugs #2022, #2079 */
5+
6+
#include <stdio.h>
7+
#include <stdlib.h>
8+
9+
int failures = 0;
10+
11+
struct foo { char a; char b; char c; };
12+
struct foo foo, bar;
13+
void f3(void)
14+
{
15+
foo.a = 6;
16+
foo.b = 6;
17+
foo.c = 6;
18+
bar.a = 1;
19+
bar.b = 2;
20+
bar.c = 3;
21+
foo = bar;
22+
printf("%d %d %d, %d %d %d (1,2,3 1,2,3)\n",
23+
foo.a, foo.b, foo.c,
24+
bar.a, bar.b, bar.c);
25+
if ((foo.a != 1) || (foo.b != 2) || (foo.c != 3) ||
26+
(bar.a != 1) || (bar.b != 2) || (bar.c != 3)) {
27+
failures++;
28+
}
29+
foo.a = 3;
30+
foo.b = 2;
31+
foo.c = 1;
32+
printf("%d %d %d, %d %d %d (3,2,1 1,2,3)\n",
33+
foo.a, foo.b, foo.c,
34+
bar.a, bar.b, bar.c);
35+
if ((foo.a != 3) || (foo.b != 2) || (foo.c != 1) ||
36+
(bar.a != 1) || (bar.b != 2) || (bar.c != 3)) {
37+
failures++;
38+
}
39+
bar.a = 5;
40+
bar.b = 6;
41+
bar.c = 7;
42+
printf("%d %d %d, %d %d %d (3,2,1 5,6,7)\n",
43+
foo.a, foo.b, foo.c,
44+
bar.a, bar.b, bar.c);
45+
if ((foo.a != 3) || (foo.b != 2) || (foo.c != 1) ||
46+
(bar.a != 5) || (bar.b != 6) || (bar.c != 7)) {
47+
failures++;
48+
}
49+
bar = foo;
50+
foo.a = 6;
51+
foo.b = 6;
52+
foo.c = 6;
53+
printf("%d %d %d, %d %d %d (6,6,6 3,2,1)\n",
54+
foo.a, foo.b, foo.c,
55+
bar.a, bar.b, bar.c);
56+
if ((foo.a != 6) || (foo.b != 6) || (foo.c != 6) ||
57+
(bar.a != 3) || (bar.b != 2) || (bar.c != 1)) {
58+
failures++;
59+
}
60+
}
61+
62+
int main(void)
63+
{
64+
f3();
65+
return failures;
66+
}

0 commit comments

Comments
 (0)