diff options
Diffstat (limited to 'test/regression/struct8.c')
-rw-r--r-- | test/regression/struct8.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/regression/struct8.c b/test/regression/struct8.c new file mode 100644 index 00000000..989c3524 --- /dev/null +++ b/test/regression/struct8.c @@ -0,0 +1,23 @@ +/* Passing structs by value */ + +#include <stdio.h> + +struct S { int x; double d; char c; }; + +struct S f(struct S s, int scale) +{ + struct S r; + r.x = s.x + scale; + r.d = s.d * scale; + r.c = 'f'; + return r; +} + +int main() +{ + struct S a = { 123, 2.718, 'a' }; + struct S b = f(a, 2); + printf("a = { %d, %f, '%c' }\n", a.x, a.d, a.c); + printf("b = { %d, %f, '%c' }\n", b.x, b.d, b.c); + return 0; +} |