Dead
[official-gcc.git] / gomp-20050608-branch / gcc / testsuite / gcc.target / x86_64 / abi / test_varargs.c
blobe6d99461d2c4020b9d24d5dbc00973b1fb074111
1 /* Test variable number of arguments passed to functions. For now this is
2 just a simple test to see if it's working. */
4 #include <stdarg.h>
5 #include "defines.h"
8 #define ARG_INT 1
9 #define ARG_DOUBLE 2
10 #define ARG_POINTER 3
12 union types
14 int ivalue;
15 double dvalue;
16 void *pvalue;
19 struct arg
21 int type;
22 union types value;
25 struct arg *arglist;
27 /* This tests the argumentlist to see if it matches the format string which
28 is printf-like. Nothing will be printed of course. It can handle ints,
29 doubles and void pointers. The given value will be tested against the
30 values given in arglist.
31 This test only assures that the variable argument passing is working.
32 No attempt is made to see if argument passing is done the right way.
33 Since the ABI doesn't say how it's done, checking this is not really
34 relevant. */
35 void
36 my_noprintf (char *format, ...)
38 va_list va_arglist;
39 char *c;
41 int ivalue;
42 double dvalue;
43 void *pvalue;
44 struct arg *argp = arglist;
46 va_start (va_arglist, format);
47 for (c = format; *c; c++)
48 if (*c == '%')
50 switch (*++c)
52 case 'd':
53 assert (argp->type == ARG_INT);
54 ivalue = va_arg (va_arglist, int);
55 assert (argp->value.ivalue == ivalue);
56 break;
57 case 'f':
58 assert (argp->type == ARG_DOUBLE);
59 dvalue = va_arg (va_arglist, double);
60 assert (argp->value.dvalue == dvalue);
61 break;
62 case 'p':
63 assert (argp->type == ARG_POINTER);
64 pvalue = va_arg (va_arglist, void *);
65 assert (argp->value.pvalue == pvalue);
66 break;
67 default:
68 abort ();
71 argp++;
75 int
76 main (void)
78 #ifdef CHECK_VARARGS
79 struct arg al[5];
81 al[0].type = ARG_INT;
82 al[0].value.ivalue = 256;
83 al[1].type = ARG_DOUBLE;
84 al[1].value.dvalue = 257.0;
85 al[2].type = ARG_POINTER;
86 al[2].value.pvalue = al;
87 al[3].type = ARG_DOUBLE;
88 al[3].value.dvalue = 258.0;
89 al[4].type = ARG_INT;
90 al[4].value.ivalue = 259;
92 arglist = al;
93 my_noprintf("%d%f%p%f%d", 256, 257.0, al, 258.0, 259);
94 #endif
96 return 0;