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 32 bits
45 /* 22 bits : really fits in 40 bits and is promoted to 64 bits
47 struct bit_flags_combo_t
{
72 /* 24 bits : promoted to 32 bits
80 /* 40 bits : promoted to 64 bits
90 /* 40 bits : promoted to 64 bits
92 struct int_char_combo_t
{
98 /*****************************************************************
100 * A do nothing function. Used to provide a point at which calls can be made.
101 *****************************************************************/
106 for (index
=0; index
<4; index
++);
109 /*****************************************************************
111 * Initializes a bit_flags_t structure. Can call this function see
112 * the call command behavior when integer arguments do not fit into
113 * registers and must be placed on the stack.
114 * OUT struct bit_flags_t *bit_flags -- structure to be filled
115 * IN unsigned a -- 0 or 1
116 * IN unsigned b -- 0 or 1
117 * IN unsigned g -- 0 or 1
118 * IN unsigned d -- 0 or 1
119 * IN unsigned e -- 0 or 1
120 * IN unsigned o -- 0 or 1
121 *****************************************************************/
123 void init_bit_flags (
124 struct bit_flags_t
*bit_flags
,
132 void init_bit_flags (bit_flags
,a
,b
,g
,d
,e
,o
)
133 struct bit_flags_t
*bit_flags
;
143 bit_flags
->alpha
= a
;
145 bit_flags
->gamma
= g
;
146 bit_flags
->delta
= d
;
147 bit_flags
->epsilon
= e
;
148 bit_flags
->omega
= o
;
151 /*****************************************************************
152 * INIT_BIT_FLAGS_COMBO :
153 * Initializes a bit_flags_combo_t structure. Can call this function
154 * to see the call command behavior when integer and character arguments
155 * do not fit into registers and must be placed on the stack.
156 * OUT struct bit_flags_combo_t *bit_flags_combo -- structure to fill
157 * IN unsigned a -- 0 or 1
158 * IN unsigned b -- 0 or 1
160 * IN unsigned g -- 0 or 1
161 * IN unsigned d -- 0 or 1
163 * IN unsigned e -- 0 or 1
164 * IN unsigned o -- 0 or 1
165 *****************************************************************/
167 void init_bit_flags_combo (
168 struct bit_flags_combo_t
*bit_flags_combo
,
178 void init_bit_flags_combo (bit_flags_combo
, a
, b
, ch1
, g
, d
, ch2
, e
, o
)
179 struct bit_flags_combo_t
*bit_flags_combo
;
191 bit_flags_combo
->alpha
= a
;
192 bit_flags_combo
->beta
= b
;
193 bit_flags_combo
->ch1
= ch1
;
194 bit_flags_combo
->gamma
= g
;
195 bit_flags_combo
->delta
= d
;
196 bit_flags_combo
->ch2
= ch2
;
197 bit_flags_combo
->epsilon
= e
;
198 bit_flags_combo
->omega
= o
;
202 /*****************************************************************
204 * OUT struct one_double_t *one_double -- structure to fill
206 *****************************************************************/
208 void init_one_double ( struct one_double_t
*one_double
, double init_val
)
210 void init_one_double (one_double
, init_val
)
211 struct one_double_t
*one_double
;
216 one_double
->double1
= init_val
;
219 /*****************************************************************
221 * OUT struct two_floats_t *two_floats -- structure to be filled
224 *****************************************************************/
226 void init_two_floats (
227 struct two_floats_t
*two_floats
,
231 void init_two_floats (two_floats
, init_val1
, init_val2
)
232 struct two_floats_t
*two_floats
;
238 two_floats
->float1
= init_val1
;
239 two_floats
->float2
= init_val2
;
242 /*****************************************************************
244 * OUT struct three_char_t *three_char -- structure to be filled
248 *****************************************************************/
250 void init_three_chars (
251 struct three_char_t
*three_char
,
256 void init_three_chars ( three_char
, init_val1
, init_val2
, init_val3
)
257 struct three_char_t
*three_char
;
264 three_char
->ch1
= init_val1
;
265 three_char
->ch2
= init_val2
;
266 three_char
->ch3
= init_val3
;
269 /*****************************************************************
271 * OUT struct five_char_t *five_char -- structure to be filled
277 *****************************************************************/
279 void init_five_chars (
280 struct five_char_t
*five_char
,
287 void init_five_chars ( five_char
, init_val1
, init_val2
, init_val3
, init_val4
, init_val5
)
288 struct five_char_t
*five_char
;
297 five_char
->ch1
= init_val1
;
298 five_char
->ch2
= init_val2
;
299 five_char
->ch3
= init_val3
;
300 five_char
->ch4
= init_val4
;
301 five_char
->ch5
= init_val5
;
304 /*****************************************************************
305 * INIT_INT_CHAR_COMBO :
306 * OUT struct int_char_combo_t *combo -- structure to be filled
309 *****************************************************************/
311 void init_int_char_combo (
312 struct int_char_combo_t
*combo
,
316 void init_int_char_combo ( combo
, init_val1
, init_val2
)
317 struct int_char_combo_t
*combo
;
323 combo
->int1
= init_val1
;
324 combo
->ch1
= init_val2
;
327 /*****************************************************************
329 * OUT struct small_rep_into_t *small_struct -- structure to be filled
331 *****************************************************************/
333 void init_struct_rep(
334 struct small_rep_info_t
*small_struct
,
337 void init_struct_rep( small_struct
, seed
)
338 struct small_rep_info_t
*small_struct
;
343 small_struct
->value
= 2 + (seed
*2);
344 small_struct
->head
= 0;
347 /*****************************************************************
349 * IN struct bit_flags_t bit_flags
350 ****************************************************************/
352 struct bit_flags_t
print_bit_flags (struct bit_flags_t bit_flags
)
354 struct bit_flags_t
print_bit_flags ( bit_flags
)
355 struct bit_flags_t bit_flags
;
359 if (bit_flags
.alpha
) printf("alpha\n");
360 if (bit_flags
.beta
) printf("beta\n");
361 if (bit_flags
.gamma
) printf("gamma\n");
362 if (bit_flags
.delta
) printf("delta\n");
363 if (bit_flags
.epsilon
) printf("epsilon\n");
364 if (bit_flags
.omega
) printf("omega\n");
369 /*****************************************************************
370 * PRINT_BIT_FLAGS_COMBO :
371 * IN struct bit_flags_combo_t bit_flags_combo
372 ****************************************************************/
374 struct bit_flags_combo_t
print_bit_flags_combo (struct bit_flags_combo_t bit_flags_combo
)
376 struct bit_flags_combo_t
print_bit_flags_combo ( bit_flags_combo
)
377 struct bit_flags_combo_t bit_flags_combo
;
381 if (bit_flags_combo
.alpha
) printf("alpha\n");
382 if (bit_flags_combo
.beta
) printf("beta\n");
383 if (bit_flags_combo
.gamma
) printf("gamma\n");
384 if (bit_flags_combo
.delta
) printf("delta\n");
385 if (bit_flags_combo
.epsilon
) printf("epsilon\n");
386 if (bit_flags_combo
.omega
) printf("omega\n");
387 printf("ch1: %c\tch2: %c\n", bit_flags_combo
.ch1
, bit_flags_combo
.ch2
);
388 return bit_flags_combo
;
392 /*****************************************************************
394 * IN struct one_double_t one_double
395 ****************************************************************/
397 struct one_double_t
print_one_double (struct one_double_t one_double
)
399 struct one_double_t
print_one_double ( one_double
)
400 struct one_double_t one_double
;
404 printf("Contents of one_double_t: \n\n");
405 printf("%f\n", one_double
.double1
);
410 /*****************************************************************
412 * IN struct two_floats_t two_floats
413 ****************************************************************/
415 struct two_floats_t
print_two_floats (struct two_floats_t two_floats
)
417 struct two_floats_t
print_two_floats ( two_floats
)
418 struct two_floats_t two_floats
;
422 printf("Contents of two_floats_t: \n\n");
423 printf("%f\t%f\n", two_floats
.float1
, two_floats
.float2
);
428 /*****************************************************************
429 * PRINT_THREE_CHARS :
430 * IN struct three_char_t three_char
431 ****************************************************************/
433 struct three_char_t
print_three_chars (struct three_char_t three_char
)
435 struct three_char_t
print_three_chars ( three_char
)
436 struct three_char_t three_char
;
440 printf("Contents of three_char_t: \n\n");
441 printf("%c\t%c\t%c\n", three_char
.ch1
, three_char
.ch2
, three_char
.ch3
);
446 /*****************************************************************
448 * IN struct five_char_t five_char
449 ****************************************************************/
451 struct five_char_t
print_five_chars (struct five_char_t five_char
)
453 struct five_char_t
print_five_chars ( five_char
)
454 struct five_char_t five_char
;
458 printf("Contents of five_char_t: \n\n");
459 printf("%c\t%c\t%c\t%c\t%c\n", five_char
.ch1
, five_char
.ch2
,
460 five_char
.ch3
, five_char
.ch4
,
466 /*****************************************************************
467 * PRINT_INT_CHAR_COMBO :
468 * IN struct int_char_combo_t int_char_combo
469 ****************************************************************/
471 struct int_char_combo_t
print_int_char_combo (struct int_char_combo_t int_char_combo
)
473 struct int_char_combo_t
print_int_char_combo ( int_char_combo
)
474 struct int_char_combo_t int_char_combo
;
478 printf("Contents of int_char_combo_t: \n\n");
479 printf("%d\t%c\n", int_char_combo
.int1
, int_char_combo
.ch1
);
480 return int_char_combo
;
484 /*****************************************************************
486 ****************************************************************/
488 struct small_rep_info_t
print_struct_rep(struct small_rep_info_t struct1
)
490 struct small_rep_info_t
print_struct_rep( struct1
)
491 struct small_rep_info_t struct1
;
495 printf("Contents of struct1: \n\n");
496 printf("%10d%10d\n", struct1
.value
, struct1
.head
);
506 struct array_rep_info_t
print_one_large_struct(struct array_rep_info_t linked_list1
)
508 struct array_rep_info_t
print_one_large_struct( linked_list1
)
509 struct array_rep_info_t linked_list1
;
514 printf("%10d%10d\n", linked_list1
.values
[0],
515 linked_list1
.next_index
[0]);
521 /*****************************************************************
523 * IN struct array_rep_info_t *linked_list
525 ****************************************************************/
527 void init_array_rep(struct array_rep_info_t
*linked_list
, int seed
)
529 void init_array_rep( linked_list
, seed
)
530 struct array_rep_info_t
*linked_list
;
537 for (index
= 0; index
< 10; index
++) {
539 linked_list
->values
[index
] = (2*index
) + (seed
*2);
540 linked_list
->next_index
[index
] = index
+ 1;
542 linked_list
->head
= 0;
548 /* variables for large structure testing
551 struct array_rep_info_t
*list1
;
553 /* variables for testing a small structures and a very long argument list
555 struct small_rep_info_t
*struct1
;
556 struct bit_flags_t
*flags
;
557 struct bit_flags_combo_t
*flags_combo
;
558 struct three_char_t
*three_char
;
559 struct five_char_t
*five_char
;
560 struct int_char_combo_t
*int_char_combo
;
561 struct one_double_t
*d1
;
562 struct two_floats_t
*f3
;
565 /* Allocate space for large structures
567 list1
= (struct array_rep_info_t
*)malloc(sizeof(struct array_rep_info_t
));
569 /* Initialize large structures
571 init_array_rep(list1
, 2);
573 /* Print large structures
575 print_one_large_struct(*list1
);
577 /* Allocate space for small structures
579 struct1
= (struct small_rep_info_t
*)malloc(sizeof(struct small_rep_info_t
));
580 flags
= (struct bit_flags_t
*)malloc(sizeof(struct bit_flags_t
));
581 flags_combo
= (struct bit_flags_combo_t
*)malloc(sizeof(struct bit_flags_combo_t
));
582 three_char
= (struct three_char_t
*)malloc(sizeof(struct three_char_t
));
583 five_char
= (struct five_char_t
*)malloc(sizeof(struct five_char_t
));
584 int_char_combo
= (struct int_char_combo_t
*)malloc(sizeof(struct int_char_combo_t
));
586 d1
= (struct one_double_t
*)malloc(sizeof(struct one_double_t
));
587 f3
= (struct two_floats_t
*)malloc(sizeof(struct two_floats_t
));
589 /* Initialize small structures
591 init_one_double ( d1
, 1.11111);
592 init_two_floats ( f3
, -2.345, 1.0);
593 init_bit_flags(flags
, (unsigned)1, (unsigned)0, (unsigned)1,
594 (unsigned)0, (unsigned)1, (unsigned)0 );
595 init_bit_flags_combo(flags_combo
, (unsigned)1, (unsigned)0, 'y',
596 (unsigned)1, (unsigned)0, 'n',
597 (unsigned)1, (unsigned)0 );
598 init_three_chars(three_char
, 'x', 'y', 'z');
599 init_five_chars(five_char
, 'h', 'e', 'l', 'l', 'o');
600 init_int_char_combo(int_char_combo
, 13, '!');
601 init_struct_rep(struct1
, 10);
604 /* Print small structures
606 print_one_double(*d1
);
607 print_two_floats(*f3
);
608 print_bit_flags(*flags
);
609 print_bit_flags_combo(*flags_combo
);
610 print_three_chars(*three_char
);
611 print_five_chars(*five_char
);
612 print_int_char_combo(*int_char_combo
);
613 print_struct_rep(*struct1
);