1 /*
2 * stdarg.h
3 *
4 * Provides facilities for stepping through a list of function arguments of
5 * an unknown number and type.
6 *
7 * NOTE: Gcc should provide stdarg.h, and I believe their version will work
8 * with crtdll. If necessary I think you can replace this with the GCC
9 * stdarg.h.
10 *
11 * Note that the type used in va_arg is supposed to match the actual type
12 * *after default promotions*. Thus, va_arg (..., short) is not valid.
13 *
14 * This file is part of the Mingw32 package.
15 *
16 * Contributors:
17 * Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
18 *
19 * THIS SOFTWARE IS NOT COPYRIGHTED
20 *
21 * This source code is offered for use in the public domain. You may
22 * use, modify or distribute it freely.
23 *
24 * This code is distributed in the hope that it will be useful but
25 * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
26 * DISCLAMED. This includes but is not limited to warranties of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28 *
29 * $Revision: 1.2 $
30 * $Author: noer $
31 * $Date: 1998/10/10 00:51:16 $
32 *
33 */
34
35 #ifndef _STDARG_H_
36 #define _STDARG_H_
37
38 /*
39 * Don't do any of this stuff for the resource compiler.
40 */
41 #ifndef RC_INVOKED
42
43 /*
44 * I was told that Win NT likes this.
45 */
46 #ifndef _VA_LIST_DEFINED
47 #define _VA_LIST_DEFINED
48 #endif
49
50 #ifndef _VA_LIST
51 #define _VA_LIST
52 typedef char* va_list;
53 #endif
54
55
56 /*
57 * Amount of space required in an argument list (ie. the stack) for an
58 * argument of type t.
59 */
60 #define __va_argsiz(t) \
61 (((sizeof(t) + sizeof(int) - 1) / sizeof(int)) * sizeof(int))
62
63
64 /*
65 * Start variable argument list processing by setting AP to point to the
66 * argument after pN.
67 */
68 #ifdef __GNUC__
69 /*
70 * In GNU the stack is not necessarily arranged very neatly in order to
71 * pack shorts and such into a smaller argument list. Fortunately a
72 * neatly arranged version is available through the use of __builtin_next_arg.
73 */
74 #define va_start(ap, pN) \
75 ((ap) = ((va_list) __builtin_next_arg(pN)))
76 #else
77 /*
78 * For a simple minded compiler this should work (it works in GNU too for
79 * vararg lists that don't follow shorts and such).
80 */
81 #define va_start(ap, pN) \
82 ((ap) = ((va_list) (&pN) + __va_argsiz(pN)))
83 #endif
84
85
86 /*
87 * End processing of variable argument list. In this case we do nothing.
88 */
89 #define va_end(ap) ((void)0)
90
91
92 /*
93 * Increment ap to the next argument in the list while returing a
94 * pointer to what ap pointed to first, which is of type t.
95 *
96 * We cast to void* and then to t* because this avoids a warning about
97 * increasing the alignment requirement.
98 */
99
100 #define va_arg(ap, t) \
101 (((ap) = (ap) + __va_argsiz(t)), \
102 *((t*) (void*) ((ap) - __va_argsiz(t))))
103
104 #endif /* Not RC_INVOKED */
105
106 #endif /* not _STDARG_H_ */