xref: /original-bsd/old/dbx/tests/cc/struct.c (revision baf24c0d)
1 /*
2  * Test for C structures.
3  */
4 
5 /*
6  * A simple nested structure.
7  */
8 
9 struct simple {
10     int a;
11     char b;
12     double c;
13     struct {
14 	int a;
15 	char b;
16 	double c;
17     } d;
18     int e;
19     char f;
20     double g;
21 } simple;
22 
23 /*
24  * Mutually recursive structures, using typedefs.
25  */
26 
27 typedef struct first *First;
28 typedef struct second *Second;
29 
30 struct second {
31     int b;
32     char c;
33 };
34 
35 struct first {
36     int a;
37     Second p;
38 };
39 
40 UseRecurStructs()
41 {
42     struct first b, *p;
43     struct second list;
44 
45     p = &b;
46     b.a = 3;
47     b.p = &list;
48     b.p->b = 4;
49     b.p->c = 'c';
50 }
51 
52 /*
53  * Functions returning structures.
54  */
55 
56 struct simple f(x)
57 int x;
58 {
59     struct simple s;
60 
61     s.a = x;
62     s.g = 3.14;
63     return s;
64 }
65 
66 main()
67 {
68     struct simple x;
69     struct simple *y;
70 
71     UseRecurStructs();
72     x = f(3);
73     y = &x;
74 }
75