:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / include / msvcrt / stdarg.h
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 (or is it vararg.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$
30  * $Author$
31  * $Date$
32  *
33  */
34 /* Appropriated for Reactos Crtdll by Ariadne */
35
36 #ifndef _STDARG_H_
37 #define _STDARG_H_
38
39 /*
40  * Don't do any of this stuff for the resource compiler.
41  */
42 #ifndef RC_INVOKED
43
44 /* 
45  * I was told that Win NT likes this.
46  */
47 #ifndef _VA_LIST_DEFINED
48 #define _VA_LIST_DEFINED
49 #endif
50
51 #ifndef _VA_LIST
52 #define _VA_LIST
53 typedef char* va_list;
54 #endif
55
56
57 /*
58  * Amount of space required in an argument list (ie. the stack) for an
59  * argument of type t.
60  */
61 #define __va_argsiz(t)  \
62         (((sizeof(t) + sizeof(int) - 1) / sizeof(int)) * sizeof(int))
63
64
65 /*
66  * Start variable argument list processing by setting AP to point to the
67  * argument after pN.
68  */
69 #ifdef  __GNUC__
70 /*
71  * In GNU the stack is not necessarily arranged very neatly in order to
72  * pack shorts and such into a smaller argument list. Fortunately a
73  * neatly arranged version is available through the use of __builtin_next_arg.
74  */
75 #ifndef va_start
76 #define va_start(ap, pN)        \
77         ((ap) = ((va_list) __builtin_next_arg(pN)))
78 #endif
79 #else
80 /*
81  * For a simple minded compiler this should work (it works in GNU too for
82  * vararg lists that don't follow shorts and such).
83  */
84 #define va_start(ap, pN)        \
85         ((ap) = ((va_list) (&pN) + __va_argsiz(pN)))
86 #endif
87
88
89 /*
90  * End processing of variable argument list. In this case we do nothing.
91  */
92 #ifndef va_end
93 #define va_end(ap)      ((void)0)
94 #endif
95         
96
97 /*
98  * Increment ap to the next argument in the list while returing a
99  * pointer to what ap pointed to first, which is of type t.
100  *
101  * We cast to void* and then to t* because this avoids a warning about
102  * increasing the alignment requirement.
103  */
104
105 #ifndef va_arg
106 #define va_arg(ap, t)                                   \
107          (((ap) = (ap) + __va_argsiz(t)),               \
108           *((t*) (void*) ((ap) - __va_argsiz(t))))
109 #endif
110         
111 #endif /* Not RC_INVOKED */
112
113 #endif /* not _STDARG_H_ */
114