Skip to content

Commit 71ce76b

Browse files
committed
add a test for small structs passed in sequence in varargs
1 parent e4c23d1 commit 71ce76b

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

tests/core/test_struct_varargs.c

+39-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <stdio.h>
22
#include <stdarg.h>
3+
#include <stdlib.h>
34

45
struct A {
56
int x;
@@ -21,14 +22,50 @@ void foo(int unused, ...)
2122
printf("%f\n", b.x);
2223
}
2324

24-
int main() {
25+
void a() {
2526
struct A a = {
2627
.x = 42,
2728
};
2829
struct B b = {
2930
.x = 42.314,
3031
};
3132
foo(0, a, b);
32-
return 0;
33+
}
34+
35+
struct tiny
36+
{
37+
short c;
38+
};
39+
40+
void f (int n, ...)
41+
{
42+
struct tiny x;
43+
int i;
44+
va_list ap;
45+
va_start (ap,n);
46+
for (i = 0; i < n; i++)
47+
{
48+
x = va_arg (ap,struct tiny);
49+
printf("%d : %d\n", i, x.c);
50+
if (x.c != i + 10) abort();
51+
}
52+
va_end (ap);
53+
}
54+
55+
void b ()
56+
{
57+
struct tiny x[3];
58+
struct tiny y;
59+
printf("sizeof tiny: %d (3 of them: %d)\n", sizeof(y), sizeof(x));
60+
x[0].c = 10;
61+
x[1].c = 11;
62+
x[2].c = 12;
63+
f (3, x[0], x[1], x[2]);
64+
}
65+
66+
int main() {
67+
a();
68+
b();
69+
printf("ok.\n");
3370
}
3471

tests/core/test_struct_varargs.out

+5
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
42
22
42.314000
3+
sizeof tiny: 2 (3 of them: 6)
4+
0 : 10
5+
1 : 11
6+
2 : 12
7+
ok.

0 commit comments

Comments
 (0)