5 /**************************************************************************
7 * function returning large structures, which go on the stack
8 * functions returning varied sized structs which go on in the registers.
9 ***************************************************************************/
12 /* A large structure (> 64 bits) used to test passing large structures as
16 struct array_rep_info_t
{
22 /*****************************************************************************
23 * Small structures ( <= 64 bits). These are used to test passing small
24 * structures as parameters and test argument size promotion.
25 *****************************************************************************/
29 struct small_rep_info_t
{
34 /* 6 bits : really fits in 8 bits and is promoted to 8 bits
36 struct bit_flags_char_t
{
37 unsigned char alpha
:1;
38 unsigned char beta
:1;
39 unsigned char gamma
:1;
40 unsigned char delta
:1;
41 unsigned char epsilon
:1;
42 unsigned char omega
:1;
45 /* 6 bits : really fits in 8 bits and is promoted to 16 bits
47 struct bit_flags_short_t
{
48 unsigned short alpha
:1;
49 unsigned short beta
:1;
50 unsigned short gamma
:1;
51 unsigned short delta
:1;
52 unsigned short epsilon
:1;
53 unsigned short omega
:1;
56 /* 6 bits : really fits in 8 bits and is promoted to 32 bits
67 /* 22 bits : really fits in 40 bits and is promoted to 64 bits
69 struct bit_flags_combo_t
{
94 /* 24 bits : promoted to 32 bits
102 /* 40 bits : promoted to 64 bits
112 /* 40 bits : promoted to 64 bits
114 struct int_char_combo_t
{
120 /*****************************************************************
122 * A do nothing function. Used to provide a point at which calls can be made.
123 *****************************************************************/
128 for (index
=0; index
<4; index
++); /* -break1- */
131 /*****************************************************************
132 * INIT_BIT_FLAGS_CHAR :
133 * Initializes a bit_flags_char_t structure. Can call this function see
134 * the call command behavior when integer arguments do not fit into
135 * registers and must be placed on the stack.
136 * OUT struct bit_flags_char_t *bit_flags -- structure to be filled
137 * IN unsigned a -- 0 or 1
138 * IN unsigned b -- 0 or 1
139 * IN unsigned g -- 0 or 1
140 * IN unsigned d -- 0 or 1
141 * IN unsigned e -- 0 or 1
142 * IN unsigned o -- 0 or 1
143 *****************************************************************/
144 void init_bit_flags_char (
145 struct bit_flags_char_t
*bit_flags
,
154 bit_flags
->alpha
= a
;
156 bit_flags
->gamma
= g
;
157 bit_flags
->delta
= d
;
158 bit_flags
->epsilon
= e
;
159 bit_flags
->omega
= o
;
162 /*****************************************************************
163 * INIT_BIT_FLAGS_SHORT :
164 * Initializes a bit_flags_short_t structure. Can call this function see
165 * the call command behavior when integer arguments do not fit into
166 * registers and must be placed on the stack.
167 * OUT struct bit_flags_short_t *bit_flags -- structure to be filled
168 * IN unsigned a -- 0 or 1
169 * IN unsigned b -- 0 or 1
170 * IN unsigned g -- 0 or 1
171 * IN unsigned d -- 0 or 1
172 * IN unsigned e -- 0 or 1
173 * IN unsigned o -- 0 or 1
174 *****************************************************************/
175 void init_bit_flags_short (
176 struct bit_flags_short_t
*bit_flags
,
185 bit_flags
->alpha
= a
;
187 bit_flags
->gamma
= g
;
188 bit_flags
->delta
= d
;
189 bit_flags
->epsilon
= e
;
190 bit_flags
->omega
= o
;
193 /*****************************************************************
195 * Initializes a bit_flags_t structure. Can call this function see
196 * the call command behavior when integer arguments do not fit into
197 * registers and must be placed on the stack.
198 * OUT struct bit_flags_t *bit_flags -- structure to be filled
199 * IN unsigned a -- 0 or 1
200 * IN unsigned b -- 0 or 1
201 * IN unsigned g -- 0 or 1
202 * IN unsigned d -- 0 or 1
203 * IN unsigned e -- 0 or 1
204 * IN unsigned o -- 0 or 1
205 *****************************************************************/
206 void init_bit_flags (
207 struct bit_flags_t
*bit_flags
,
216 bit_flags
->alpha
= a
;
218 bit_flags
->gamma
= g
;
219 bit_flags
->delta
= d
;
220 bit_flags
->epsilon
= e
;
221 bit_flags
->omega
= o
;
224 /*****************************************************************
225 * INIT_BIT_FLAGS_COMBO :
226 * Initializes a bit_flags_combo_t structure. Can call this function
227 * to see the call command behavior when integer and character arguments
228 * do not fit into registers and must be placed on the stack.
229 * OUT struct bit_flags_combo_t *bit_flags_combo -- structure to fill
230 * IN unsigned a -- 0 or 1
231 * IN unsigned b -- 0 or 1
233 * IN unsigned g -- 0 or 1
234 * IN unsigned d -- 0 or 1
236 * IN unsigned e -- 0 or 1
237 * IN unsigned o -- 0 or 1
238 *****************************************************************/
239 void init_bit_flags_combo (
240 struct bit_flags_combo_t
*bit_flags_combo
,
251 bit_flags_combo
->alpha
= a
;
252 bit_flags_combo
->beta
= b
;
253 bit_flags_combo
->ch1
= ch1
;
254 bit_flags_combo
->gamma
= g
;
255 bit_flags_combo
->delta
= d
;
256 bit_flags_combo
->ch2
= ch2
;
257 bit_flags_combo
->epsilon
= e
;
258 bit_flags_combo
->omega
= o
;
262 /*****************************************************************
264 * OUT struct one_double_t *one_double -- structure to fill
266 *****************************************************************/
267 void init_one_double ( struct one_double_t
*one_double
, double init_val
)
270 one_double
->double1
= init_val
;
273 /*****************************************************************
275 * OUT struct two_floats_t *two_floats -- structure to be filled
278 *****************************************************************/
279 void init_two_floats (
280 struct two_floats_t
*two_floats
,
285 two_floats
->float1
= init_val1
;
286 two_floats
->float2
= init_val2
;
289 /*****************************************************************
291 * OUT struct three_char_t *three_char -- structure to be filled
295 *****************************************************************/
296 void init_three_chars (
297 struct three_char_t
*three_char
,
303 three_char
->ch1
= init_val1
;
304 three_char
->ch2
= init_val2
;
305 three_char
->ch3
= init_val3
;
308 /*****************************************************************
310 * OUT struct five_char_t *five_char -- structure to be filled
316 *****************************************************************/
317 void init_five_chars (
318 struct five_char_t
*five_char
,
326 five_char
->ch1
= init_val1
;
327 five_char
->ch2
= init_val2
;
328 five_char
->ch3
= init_val3
;
329 five_char
->ch4
= init_val4
;
330 five_char
->ch5
= init_val5
;
333 /*****************************************************************
334 * INIT_INT_CHAR_COMBO :
335 * OUT struct int_char_combo_t *combo -- structure to be filled
338 *****************************************************************/
339 void init_int_char_combo (
340 struct int_char_combo_t
*combo
,
345 combo
->int1
= init_val1
;
346 combo
->ch1
= init_val2
;
349 /*****************************************************************
351 * OUT struct small_rep_into_t *small_struct -- structure to be filled
353 *****************************************************************/
354 void init_struct_rep(
355 struct small_rep_info_t
*small_struct
,
359 small_struct
->value
= 2 + (seed
*2);
360 small_struct
->head
= 0;
363 /*****************************************************************
364 * PRINT_BIT_FLAGS_CHAR :
365 * IN struct bit_flags_char_t bit_flags
366 ****************************************************************/
367 struct bit_flags_char_t
print_bit_flags_char (struct bit_flags_char_t bit_flags
)
370 if (bit_flags
.alpha
) printf("alpha\n");
371 if (bit_flags
.beta
) printf("beta\n");
372 if (bit_flags
.gamma
) printf("gamma\n");
373 if (bit_flags
.delta
) printf("delta\n");
374 if (bit_flags
.epsilon
) printf("epsilon\n");
375 if (bit_flags
.omega
) printf("omega\n");
380 /*****************************************************************
381 * PRINT_BIT_FLAGS_SHORT :
382 * IN struct bit_flags_short_t bit_flags
383 ****************************************************************/
384 struct bit_flags_short_t
print_bit_flags_short (struct bit_flags_short_t bit_flags
)
387 if (bit_flags
.alpha
) printf("alpha\n");
388 if (bit_flags
.beta
) printf("beta\n");
389 if (bit_flags
.gamma
) printf("gamma\n");
390 if (bit_flags
.delta
) printf("delta\n");
391 if (bit_flags
.epsilon
) printf("epsilon\n");
392 if (bit_flags
.omega
) printf("omega\n");
397 /*****************************************************************
399 * IN struct bit_flags_t bit_flags
400 ****************************************************************/
401 struct bit_flags_t
print_bit_flags (struct bit_flags_t bit_flags
)
404 if (bit_flags
.alpha
) printf("alpha\n");
405 if (bit_flags
.beta
) printf("beta\n");
406 if (bit_flags
.gamma
) printf("gamma\n");
407 if (bit_flags
.delta
) printf("delta\n");
408 if (bit_flags
.epsilon
) printf("epsilon\n");
409 if (bit_flags
.omega
) printf("omega\n");
414 /*****************************************************************
415 * PRINT_BIT_FLAGS_COMBO :
416 * IN struct bit_flags_combo_t bit_flags_combo
417 ****************************************************************/
418 struct bit_flags_combo_t
print_bit_flags_combo (struct bit_flags_combo_t bit_flags_combo
)
421 if (bit_flags_combo
.alpha
) printf("alpha\n");
422 if (bit_flags_combo
.beta
) printf("beta\n");
423 if (bit_flags_combo
.gamma
) printf("gamma\n");
424 if (bit_flags_combo
.delta
) printf("delta\n");
425 if (bit_flags_combo
.epsilon
) printf("epsilon\n");
426 if (bit_flags_combo
.omega
) printf("omega\n");
427 printf("ch1: %c\tch2: %c\n", bit_flags_combo
.ch1
, bit_flags_combo
.ch2
);
428 return bit_flags_combo
;
432 /*****************************************************************
434 * IN struct one_double_t one_double
435 ****************************************************************/
436 struct one_double_t
print_one_double (struct one_double_t one_double
)
439 printf("Contents of one_double_t: \n\n");
440 printf("%f\n", one_double
.double1
);
445 /*****************************************************************
447 * IN struct two_floats_t two_floats
448 ****************************************************************/
449 struct two_floats_t
print_two_floats (struct two_floats_t two_floats
)
452 printf("Contents of two_floats_t: \n\n");
453 printf("%f\t%f\n", two_floats
.float1
, two_floats
.float2
);
458 /*****************************************************************
459 * PRINT_THREE_CHARS :
460 * IN struct three_char_t three_char
461 ****************************************************************/
462 struct three_char_t
print_three_chars (struct three_char_t three_char
)
465 printf("Contents of three_char_t: \n\n");
466 printf("%c\t%c\t%c\n", three_char
.ch1
, three_char
.ch2
, three_char
.ch3
);
471 /*****************************************************************
473 * IN struct five_char_t five_char
474 ****************************************************************/
475 struct five_char_t
print_five_chars (struct five_char_t five_char
)
478 printf("Contents of five_char_t: \n\n");
479 printf("%c\t%c\t%c\t%c\t%c\n", five_char
.ch1
, five_char
.ch2
,
480 five_char
.ch3
, five_char
.ch4
,
486 /*****************************************************************
487 * PRINT_INT_CHAR_COMBO :
488 * IN struct int_char_combo_t int_char_combo
489 ****************************************************************/
490 struct int_char_combo_t
print_int_char_combo (struct int_char_combo_t int_char_combo
)
493 printf("Contents of int_char_combo_t: \n\n");
494 printf("%d\t%c\n", int_char_combo
.int1
, int_char_combo
.ch1
);
495 return int_char_combo
;
499 /*****************************************************************
501 ****************************************************************/
502 struct small_rep_info_t
print_struct_rep(struct small_rep_info_t struct1
)
505 printf("Contents of struct1: \n\n");
506 printf("%10d%10d\n", struct1
.value
, struct1
.head
);
515 struct array_rep_info_t
print_one_large_struct(struct array_rep_info_t linked_list1
)
519 printf("%10d%10d\n", linked_list1
.values
[0],
520 linked_list1
.next_index
[0]);
526 /*****************************************************************
528 * IN struct array_rep_info_t *linked_list
530 ****************************************************************/
531 void init_array_rep(struct array_rep_info_t
*linked_list
, int seed
)
536 for (index
= 0; index
< 10; index
++) {
538 linked_list
->values
[index
] = (2*index
) + (seed
*2);
539 linked_list
->next_index
[index
] = index
+ 1;
541 linked_list
->head
= 0;
547 /* variables for large structure testing
550 struct array_rep_info_t
*list1
;
552 /* variables for testing a small structures and a very long argument list
554 struct small_rep_info_t
*struct1
;
555 struct bit_flags_char_t
*cflags
;
556 struct bit_flags_short_t
*sflags
;
557 struct bit_flags_t
*flags
;
558 struct bit_flags_combo_t
*flags_combo
;
559 struct three_char_t
*three_char
;
560 struct five_char_t
*five_char
;
561 struct int_char_combo_t
*int_char_combo
;
562 struct one_double_t
*d1
;
563 struct two_floats_t
*f3
;
566 /* Allocate space for large structures
568 list1
= (struct array_rep_info_t
*)malloc(sizeof(struct array_rep_info_t
));
570 /* Initialize large structures
572 init_array_rep(list1
, 2);
574 /* Print large structures
576 print_one_large_struct(*list1
);
578 /* Allocate space for small structures
580 struct1
= (struct small_rep_info_t
*)malloc(sizeof(struct small_rep_info_t
));
581 cflags
= (struct bit_flags_char_t
*)malloc(sizeof(struct bit_flags_char_t
));
582 sflags
= (struct bit_flags_short_t
*)malloc(sizeof(struct bit_flags_short_t
));
583 flags
= (struct bit_flags_t
*)malloc(sizeof(struct bit_flags_t
));
584 flags_combo
= (struct bit_flags_combo_t
*)malloc(sizeof(struct bit_flags_combo_t
));
585 three_char
= (struct three_char_t
*)malloc(sizeof(struct three_char_t
));
586 five_char
= (struct five_char_t
*)malloc(sizeof(struct five_char_t
));
587 int_char_combo
= (struct int_char_combo_t
*)malloc(sizeof(struct int_char_combo_t
));
589 d1
= (struct one_double_t
*)malloc(sizeof(struct one_double_t
));
590 f3
= (struct two_floats_t
*)malloc(sizeof(struct two_floats_t
));
592 /* Initialize small structures
594 init_one_double ( d1
, 1.11111);
595 init_two_floats ( f3
, -2.345, 1.0);
596 init_bit_flags_char(cflags
, (unsigned)1, (unsigned)0, (unsigned)1,
597 (unsigned)0, (unsigned)1, (unsigned)0 );
598 init_bit_flags_short(sflags
, (unsigned)1, (unsigned)0, (unsigned)1,
599 (unsigned)0, (unsigned)1, (unsigned)0 );
600 init_bit_flags(flags
, (unsigned)1, (unsigned)0, (unsigned)1,
601 (unsigned)0, (unsigned)1, (unsigned)0 );
602 init_bit_flags_combo(flags_combo
, (unsigned)1, (unsigned)0, 'y',
603 (unsigned)1, (unsigned)0, 'n',
604 (unsigned)1, (unsigned)0 );
605 init_three_chars(three_char
, 'x', 'y', 'z');
606 init_five_chars(five_char
, 'h', 'e', 'l', 'l', 'o');
607 init_int_char_combo(int_char_combo
, 13, '!');
608 init_struct_rep(struct1
, 10);
611 /* Print small structures
613 print_one_double(*d1
);
614 print_two_floats(*f3
);
615 print_bit_flags_char(*cflags
);
616 print_bit_flags_short(*sflags
);
617 print_bit_flags(*flags
);
618 print_bit_flags_combo(*flags_combo
);
619 print_three_chars(*three_char
);
620 print_five_chars(*five_char
);
621 print_int_char_combo(*int_char_combo
);
622 print_struct_rep(*struct1
);
624 loop_count(); /* -finish2- */
626 return 0; /* -finish1- */