1 /* C99 6.5.2.2 Function calls.
2    Test passing varargs of the combination of decimal float types and
3    other types.  */
4 
5 #include <stdarg.h>
6 #include "dfp-dbg.h"
7 
8 /* Supposing the list of varying number of arguments is:
9    unsigned int, _Decimal128, double, _Decimal32, _Decimal64.  */
10 
11 static _Decimal32
vararg_d32(unsigned arg,...)12 vararg_d32 (unsigned arg, ...)
13 {
14   va_list ap;
15   _Decimal32 result;
16 
17   va_start (ap, arg);
18 
19   va_arg (ap, unsigned int);
20   va_arg (ap, _Decimal128);
21   va_arg (ap, double);
22   result = va_arg (ap, _Decimal32);
23 
24   va_end (ap);
25   return result;
26 }
27 
28 static _Decimal32
vararg_d64(unsigned arg,...)29 vararg_d64 (unsigned arg, ...)
30 {
31   va_list ap;
32   _Decimal64 result;
33 
34   va_start (ap, arg);
35 
36   va_arg (ap, unsigned int);
37   va_arg (ap, _Decimal128);
38   va_arg (ap, double);
39   va_arg (ap, _Decimal32);
40   result = va_arg (ap, _Decimal64);
41 
42   va_end (ap);
43   return result;
44 }
45 
46 static _Decimal128
vararg_d128(unsigned arg,...)47 vararg_d128 (unsigned arg, ...)
48 {
49   va_list ap;
50   _Decimal128 result;
51 
52   va_start (ap, arg);
53 
54   va_arg (ap, unsigned int);
55   result = va_arg (ap, _Decimal128);
56 
57   va_end (ap);
58   return result;
59 }
60 
61 static unsigned int
vararg_int(unsigned arg,...)62 vararg_int (unsigned arg, ...)
63 {
64   va_list ap;
65   unsigned int result;
66 
67   va_start (ap, arg);
68 
69   result = va_arg (ap, unsigned int);
70 
71   va_end (ap);
72   return result;
73 }
74 
75 static double
vararg_double(unsigned arg,...)76 vararg_double (unsigned arg, ...)
77 {
78   va_list ap;
79   float result;
80 
81   va_start (ap, arg);
82 
83   va_arg (ap, unsigned int);
84   va_arg (ap, _Decimal128);
85   result = va_arg (ap, double);
86 
87   va_end (ap);
88   return result;
89 }
90 
91 
92 int
main()93 main ()
94 {
95   if (vararg_d32 (3, 0, 1.0dl, 2.0, 3.0df, 4.0dd) != 3.0df) FAILURE
96   if (vararg_d64 (4, 0, 1.0dl, 2.0, 3.0df, 4.0dd) != 4.0dd) FAILURE
97   if (vararg_d128 (1, 0, 1.0dl, 2.0, 3.0df, 4.0dd) != 1.0dl) FAILURE
98   if (vararg_int (0, 0, 1.0dl, 2.0, 3.0df, 4.0dd) != 0) FAILURE
99   if (vararg_double (2, 0, 1.0dl, 2.0, 3.0df, 4.0dd) != 2.0) FAILURE
100 
101   FINISH
102 }
103