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