annotate deep-nested-struct.c @ 0:e59ebf6fe2b0

Initial revision
author kinjo
date Sat, 26 Nov 2005 11:36:16 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
1 // to test a deep-nested struct
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
2 // this example tests a 2 nested struct
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
3 #define NULL ((void*)0)
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
4 struct nest1{
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
5 int i;
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
6 int j;
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
7 char k;
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
8 };
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
9 struct nest0{
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
10 int huga;
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
11 long hoge;
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
12 float aho;
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
13 struct nest1 n1;
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
14 };
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
15 struct nest{
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
16 char *str;
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
17 char *p;
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
18 void *env;
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
19 code (*ret)(int);
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
20 struct nest0 n0;
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
21 };
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
22 code
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
23 dmpn2(code(*ret)(int), void *env)
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
24 {
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
25 goto ret(0), env;
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
26 }
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
27 code
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
28 dmpn1(struct nest1 *test1, code(*ret)(int), void *env)
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
29 {
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
30 printf("dmpn1: %d %d %d\n",
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
31 test1->i,
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
32 test1->j,
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
33 test1->k);
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
34 goto dmpn2(ret,env);
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
35 }
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
36 code
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
37 dmpn0(struct nest0 *test0, code(*ret)(), void *env)
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
38 {
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
39 printf("dmpn0: %d %ld %f\n",
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
40 test0->huga,
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
41 test0->hoge,
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
42 test0->aho);
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
43 goto dmpn1(&(test0->n1), ret, env);
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
44 }
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
45 code
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
46 dmpn(struct nest *test)
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
47 {
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
48 printf("dmpn: %x %x\n", test->str, test->p);
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
49 goto dmpn0(&(test->n0), test->ret, test->env);
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
50 }
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
51 void
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
52 dmp(struct nest *n)
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
53 {
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
54 n->ret=return;
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
55 n->env=environment;
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
56 goto dmpn(n);
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
57 }
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
58 int
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
59 main()
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
60 {
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
61 struct nest test;
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
62 test.str=NULL;
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
63 test.p=NULL;
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
64 test.n0.huga=1;
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
65 test.n0.hoge=2;
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
66 test.n0.aho=3.0;
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
67 test.n0.n1.i=10;
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
68 test.n0.n1.j=20;
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
69 test.n0.n1.k=30;
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
70 // dmp(&test);
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
71 return(0);
e59ebf6fe2b0 Initial revision
kinjo
parents:
diff changeset
72 }