152
|
1
|
|
2 #include <assert.h>
|
|
3 #include <stdio.h>
|
|
4 #include <stdint.h>
|
|
5
|
|
6 #if __cplusplus
|
|
7 extern "C" {
|
|
8 #endif
|
|
9
|
|
10 struct Foo1 { char c; };
|
|
11
|
|
12 struct Foo1 ctest1()
|
|
13 {
|
|
14 struct Foo1 f;
|
|
15
|
|
16 f.c = 3;
|
|
17 return f;
|
|
18 }
|
|
19
|
|
20 struct Foo2 { short s; };
|
|
21
|
|
22 struct Foo2 ctest2()
|
|
23 {
|
|
24 struct Foo2 f;
|
|
25
|
|
26 f.s = 0x1234;
|
|
27 return f;
|
|
28 }
|
|
29
|
|
30 struct Foo3 { char c; short s; };
|
|
31
|
|
32 struct Foo3 ctest3()
|
|
33 {
|
|
34 struct Foo3 f;
|
|
35
|
|
36 f.s = 0x5678;
|
|
37 return f;
|
|
38 }
|
|
39
|
|
40
|
|
41 struct Foo4 { int i; };
|
|
42
|
|
43 struct Foo4 ctest4()
|
|
44 {
|
|
45 struct Foo4 f;
|
|
46
|
|
47 f.i = 0x12345678;
|
|
48 return f;
|
|
49 }
|
|
50
|
|
51 struct Foo5 { int i, j; };
|
|
52
|
|
53 struct Foo5 ctest5()
|
|
54 {
|
|
55 struct Foo5 f;
|
|
56
|
|
57 f.i = 0x12345678;
|
|
58 f.j = 0x21436587;
|
|
59 return f;
|
|
60 }
|
|
61
|
|
62
|
|
63 struct Foo6 { int i, j, k; };
|
|
64
|
|
65 struct Foo6 ctest6()
|
|
66 {
|
|
67 struct Foo6 f;
|
|
68
|
|
69 f.i = 0x12345678;
|
|
70 f.j = 0x21463587;
|
|
71 f.k = 0x24163857;
|
|
72 return f;
|
|
73 }
|
|
74
|
|
75 struct S7 { float a,b; };
|
|
76
|
|
77 struct S7 ctest10()
|
|
78 {
|
|
79 struct S7 f;
|
|
80
|
|
81 f.a = 2.5;
|
|
82 f.b = 1.5;
|
|
83 return f;
|
|
84 }
|
|
85
|
|
86 // =================================
|
|
87
|
|
88 char ctest7(char c)
|
|
89 {
|
|
90 return c + 1;
|
|
91 }
|
|
92
|
|
93 unsigned char ctest8(unsigned char c)
|
|
94 {
|
|
95 return c + 1;
|
|
96 }
|
|
97
|
|
98 signed char ctest9(signed char c)
|
|
99 {
|
|
100 return c + 1;
|
|
101 }
|
|
102
|
|
103 /***********************************************/
|
|
104
|
|
105 void ctestrir(int x1, int x2, int x3, int x4, int x5, int x6, long double a, int b, long double c)
|
|
106 {
|
|
107 assert(a == 100.0);
|
|
108 assert(b == 67);
|
|
109 assert(c == 200.0);
|
|
110 }
|
|
111
|
|
112 /***********************************************/
|
|
113
|
|
114 extern void dtestrir(int x1, int x2, int x3, int x4, int x5, int x6, long double a, int b, long double c);
|
|
115
|
|
116 void test4()
|
|
117 {
|
|
118 dtestrir(1,2,3,4,5,6, 300.0, 68, 401.0);
|
|
119 }
|
|
120
|
|
121 /**********************************************/
|
|
122
|
|
123 typedef struct S11 {
|
|
124 char a;
|
|
125 char b;
|
|
126 char c;
|
|
127 } S11;
|
|
128
|
|
129 S11 ctest11(char x, S11 s, char y) {
|
|
130 printf("C sz = %d\n", (int)sizeof(S11));
|
|
131 assert(sizeof(S11) == 3);
|
|
132 printf("x = %d\n", (int)x);
|
|
133 printf("s.a = %d\n", (int)s.a);
|
|
134 printf("s.b = %d\n", (int)s.b);
|
|
135 printf("s.c = %d\n", (int)s.c);
|
|
136 printf("y = %d\n", (int)y);
|
|
137 return s;
|
|
138 }
|
|
139
|
|
140 /**********************************************/
|
|
141
|
|
142 typedef struct S12 {
|
|
143 char a,d;
|
|
144 char b,e;
|
|
145 char c;
|
|
146 } S12;
|
|
147
|
|
148 S12 ctest12(char x, S12 s, char y) {
|
|
149 printf("C sz = %d\n", (int)sizeof(S12));
|
|
150 assert(sizeof(S12) == 5);
|
|
151 printf("x = %d\n", (int)x);
|
|
152 printf("s.a = %d\n", (int)s.a);
|
|
153 printf("s.b = %d\n", (int)s.b);
|
|
154 printf("s.c = %d\n", (int)s.c);
|
|
155 printf("y = %d\n", (int)y);
|
|
156 return s;
|
|
157 }
|
|
158
|
|
159
|
|
160 /**********************************************/
|
|
161
|
|
162 typedef struct S13 {
|
|
163 short a;
|
|
164 short b;
|
|
165 short c;
|
|
166 } S13;
|
|
167
|
|
168 S13 ctest13(char x, S13 s, char y) {
|
|
169 printf("C sz = %d\n", (int)sizeof(S13));
|
|
170 assert(sizeof(S13) == 6);
|
|
171 printf("x = %d\n", (int)x);
|
|
172 printf("s.a = %d\n", (int)s.a);
|
|
173 printf("s.b = %d\n", (int)s.b);
|
|
174 printf("s.c = %d\n", (int)s.c);
|
|
175 printf("y = %d\n", (int)y);
|
|
176 return s;
|
|
177 }
|
|
178
|
|
179
|
|
180 /**********************************************/
|
|
181
|
|
182 typedef struct S14 {
|
|
183 char a,d,e,f;
|
|
184 char b,g;
|
|
185 char c;
|
|
186 } S14;
|
|
187
|
|
188 S14 ctest14(char x, S14 s, char y) {
|
|
189 printf("C sz = %d\n", (int)sizeof(S14));
|
|
190 assert(sizeof(S14) == 7);
|
|
191 printf("x = %d\n", (int)x);
|
|
192 printf("s.a = %d\n", (int)s.a);
|
|
193 printf("s.b = %d\n", (int)s.b);
|
|
194 printf("s.c = %d\n", (int)s.c);
|
|
195 printf("y = %d\n", (int)y);
|
|
196 return s;
|
|
197 }
|
|
198
|
|
199
|
|
200 /**********************************************/
|
|
201
|
|
202 typedef struct S15 {
|
|
203 char a,d,e,f;
|
|
204 char b,g,h,i;
|
|
205 char c;
|
|
206 } S15;
|
|
207
|
|
208 S15 ctest15(char x, S15 s, char y) {
|
|
209 printf("C sz = %d\n", (int)sizeof(S15));
|
|
210 assert(sizeof(S15) == 9);
|
|
211 printf("x = %d\n", (int)x);
|
|
212 printf("s.a = %d\n", (int)s.a);
|
|
213 printf("s.b = %d\n", (int)s.b);
|
|
214 printf("s.c = %d\n", (int)s.c);
|
|
215 printf("y = %d\n", (int)y);
|
|
216 return s;
|
|
217 }
|
|
218
|
|
219
|
|
220 /**********************************************/
|
|
221
|
|
222 typedef struct S16 {
|
|
223 char a[5];
|
|
224 #ifdef __GNUC__
|
|
225 struct __attribute__((packed))
|
|
226 #else
|
|
227 #pragma pack(push, 1)
|
|
228 struct
|
|
229 #endif
|
|
230 {
|
|
231 char b;
|
|
232 int c;
|
|
233 };
|
|
234 #ifndef __GNUC__
|
|
235 #pragma pack(pop)
|
|
236 #endif
|
|
237 } S16;
|
|
238
|
|
239 S16 ctest16(char x, S16 s, char y) {
|
|
240 printf("C sz = %d\n", (int)sizeof(S16));
|
|
241 assert(sizeof(S16) == 10);
|
|
242 printf("x = %d\n", (int)x);
|
|
243 printf("s.a = %.*s\n", 5, s.a);
|
|
244 printf("s.b = %d\n", (int)s.b);
|
|
245 printf("s.c = %d\n", s.c);
|
|
246 printf("y = %d\n", (int)y);
|
|
247 return s;
|
|
248 }
|
|
249
|
|
250
|
|
251
|
|
252 #if __cplusplus
|
|
253 }
|
|
254 #endif
|
|
255
|