-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomp_lit.c
68 lines (44 loc) · 922 Bytes
/
comp_lit.c
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
/* vim:ts=4:sw=4:et:so=10:
* Vim modeline for consistent editor settings across files.
*
* comp_lit.c
* Example using compund literals.
*
*/
#include <stdio.h>
struct s {
int a;
int b;
} gs;
struct d {
int i;
char *s;
};
void foo(int);
int bar(struct s);
void baz(struct d);
int main(int argc, char *argv[]) {
//struct s ls;
struct d ds = {.i = 0, .s = "initialized"};
foo(1);
baz(ds);
baz((struct d){.i = 1, .s = "random"});
return 0;
}
void foo(int x) {
int y;
struct s fs = {.a = x, .b = x};
y = bar(fs);
printf("foo: y = %d\n", y);
printf("foo: bar() = %d\n", bar((struct s){.b = 3, .a = 0}));
}
int bar(struct s ps) {
if ( ps.a > 0)
printf("bar: a = %d\tb=%d\n", ps.a, ps.b);
else
return ps.b;
return ps.b - ps.a;
}
void baz(struct d db) {
printf("baz: %s\n", db.s);
}