annotate test/inline.c @ 460:2859bb9d5fb3

volatile/const
author kono
date Thu, 02 Dec 2004 12:07:16 +0900
parents 9fc266d4010f
children 3d921f7a8e74
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
459
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
1 const int a = 5,b = -3;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
2 int kkkk = 333;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
3 static const int as = 5,bs = -3;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
4 const char hoo[] = "test";
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
5 static const char haa[] = "test";
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
6 static inline const int f(int k);
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
7
460
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
8 volatile const int i = 3;
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
9
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
10 extern int printf(char *,...);
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
11 int
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
12 main0()
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
13 {
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
14 volatile const int j = 3;
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
15 switch(i) {
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
16 case 1: printf("#0015:1\n"); break;
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
17 case 2: printf("#0016:2\n"); break;
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
18 case 3: printf("#0017:3\n"); break;
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
19 case 4: printf("#0018:4\n"); break;
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
20 }
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
21 switch(j) {
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
22 case 1: printf("#0021:1\n"); break;
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
23 case 2: printf("#0022:2\n"); break;
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
24 case 3: printf("#0023:3\n"); break;
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
25 case 4: printf("#0024:4\n"); break;
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
26 }
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
27 return 0;
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
28 }
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
29
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
30
459
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
31 extern int printf(char *,...);
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
32
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
33 static inline const int f(int k)
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
34 {
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
35 return k+1;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
36 }
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
37
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
38 inline int in1(int i,int j)
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
39 {
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
40 if (i>j) return j;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
41 else return i;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
42 }
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
43
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
44 static
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
45 inline int ins(int i,int j)
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
46 {
460
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
47 printf("#0046:%d %d\n",i,j);
459
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
48 if (f(i)>j) return j;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
49 else return i;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
50 }
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
51
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
52 static
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
53 inline int ins1(int i,int j)
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
54 {
460
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
55 printf("#0054:%d %d\n",i,j);
459
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
56 if (f(i)>j) return j;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
57 else return i;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
58 }
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
59
460
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
60 inline __attribute__((always_inline)) int in2(int p,int i,int j)
459
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
61 {
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
62 int k = 0,m;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
63 do {
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
64 k += 3;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
65 } while ( k < j);
460
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
66 printf("#0065: %d do %d\n",p,k);
459
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
67
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
68 while (k < j) {
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
69 k -= 3;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
70 } while ( k < j);
460
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
71 printf("#0070: %d while %d\n",p,k);
459
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
72
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
73 m = 0;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
74 for(k=0;k<j;k++) {
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
75 m += k;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
76 }
460
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
77 printf("#0076: %d for %d\n",p,m);
459
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
78
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
79 switch(i) {
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
80 case 1: k = 1;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
81 break;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
82 case 2: k = 2;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
83 break;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
84 case 3: k = 3;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
85 break;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
86 case 4: k = 4;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
87 break;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
88 default: k = 5;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
89 }
460
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
90 printf("#0089: %d switch %d\n",p,k);
459
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
91
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
92 for(k=0;k<j;k++) {
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
93 i += k;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
94 if (k<3) continue;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
95 }
460
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
96 printf("#0095: %d for %d\n",p,i);
459
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
97 goto hoge;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
98 hage:
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
99 goto hage;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
100 hoge:
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
101 return 0;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
102
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
103 }
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
104
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
105 int (*fnp)(int i,int j);
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
106
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
107 int (*fnp3)(int i,int j,int k);
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
108
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
109 void
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
110 a0(int k,int j)
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
111 {
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
112 int k1,j1;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
113 const int v=3,x=6;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
114 // a = 10;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
115
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
116 k1 = in1(a,b);
460
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
117 printf("#0116:%d %d %d\n",a,b,k1);
459
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
118 j1 = in1(k,j-6)+f(k1);
460
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
119 printf("#0118:%d %d %s\n",k1,j1,hoo);
459
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
120 k1 = &v-&x>0? &v-&x : &x-&v;
460
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
121 printf("#0120:v-x: %d\n",k1);
459
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
122
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
123 k1 = ins(a,b);
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
124 j1 = ins(k,j-6)+f(k1);
460
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
125 printf("#0124:%d %d %s\n",k1,j1,haa);
459
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
126
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
127 k1 = ins(as,bs);
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
128 j1 = ins(k,j-6)+f(k1);
460
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
129 printf("#0128:%d %d %s\n",k1,j1,haa);
459
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
130
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
131 k1 = ins(v,x);
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
132 j1 = ins(k,j-6)+f(v);
460
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
133 printf("#0132:%d %d %s\n",k1,j1,haa);
459
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
134
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
135 k1 = fnp(v,x);
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
136 j1 = ins1(k,j-6)+f(v);
460
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
137 printf("#0136:%d %d %s\n",k1,j1,haa);
459
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
138 }
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
139
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
140 void
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
141 a1(int k,int j)
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
142 {
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
143 in2(1,k,j);
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
144 in2(2,3,10);
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
145 in2(3,k,10);
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
146 in2(4,2,j);
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
147 in2(5,2,1);
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
148 in2(6,0,2);
460
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
149 in2(8,j*3,in2(7,k+3,10-j));
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
150 fnp3(9,0,2);
459
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
151 }
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
152
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
153 int
460
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
154 main(int ac,char *av[])
459
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
155 {
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
156 fnp = ins1;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
157 a0(5,6);
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
158 a0(-9,6);
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
159 fnp3 = in2;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
160 a1(9,10);
460
2859bb9d5fb3 volatile/const
kono
parents: 459
diff changeset
161 main0(ac,av);
459
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
162 return 0;
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
163 }
9fc266d4010f *** empty log message ***
kono
parents:
diff changeset
164