more stack for boot
[minix.git] / include / stdarg.h
blob40a4298f8229343b83f6e1c1c663c43c3d0b6e38
1 /* The <stdarg.h> header is ANSI's way to handle variable numbers of params.
2 * Some programming languages require a function that is declared with n
3 * parameters to be called with n parameters. C does not. A function may
4 * called with more parameters than it is declared with. The well-known
5 * printf function, for example, may have arbitrarily many parameters.
6 * The question arises how one can access all the parameters in a portable
7 * way. The C standard defines three macros that programs can use to
8 * advance through the parameter list. The definition of these macros for
9 * MINIX are given in this file. The three macros are:
11 * va_start(ap, parmN) prepare to access parameters
12 * va_arg(ap, type) get next parameter value and type
13 * va_end(ap) access is finished
15 * Ken Thompson's famous line from V6 UNIX is equally applicable to this file:
17 * "You are not expected to understand this"
21 #ifndef _STDARG_H
22 #define _STDARG_H
24 #ifdef __GNUC__
25 /* The GNU C-compiler uses its own, but similar varargs mechanism. */
27 typedef char *va_list;
29 /* Amount of space required in an argument list for an arg of type TYPE.
30 * TYPE may alternatively be an expression whose type is used.
33 #define __va_rounded_size(TYPE) \
34 (((sizeof (TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int))
36 #if __GNUC__ < 2
38 #ifndef __sparc__
39 #define va_start(AP, LASTARG) \
40 (AP = ((char *) &(LASTARG) + __va_rounded_size (LASTARG)))
41 #else
42 #define va_start(AP, LASTARG) \
43 (__builtin_saveregs (), \
44 AP = ((char *) &(LASTARG) + __va_rounded_size (LASTARG)))
45 #endif
47 void va_end (va_list); /* Defined in gnulib */
48 #define va_end(AP)
50 #define va_arg(AP, TYPE) \
51 (AP += __va_rounded_size (TYPE), \
52 *((TYPE *) (AP - __va_rounded_size (TYPE))))
54 #else /* __GNUC__ >= 2 */
56 #define va_start(ap, last) __builtin_va_start((ap), (last))
57 #define va_arg(ap, type) __builtin_va_arg((ap), type)
58 #define va_end(ap) __builtin_va_end(ap)
59 #define va_copy(dest, src) __builtin_va_copy((dest), (src))
61 #endif /* __GNUC__ >= 2 */
63 #else /* not __GNUC__ */
65 typedef char *va_list;
67 #define __vasz(x) ((sizeof(x)+sizeof(int)-1) & ~(sizeof(int) -1))
69 #define va_start(ap, parmN) ((ap) = (va_list)&parmN + __vasz(parmN))
70 #define va_arg(ap, type) \
71 (*((type *)((va_list)((ap) = (void *)((va_list)(ap) + __vasz(type))) \
72 - __vasz(type))))
73 #define va_copy(ap2, ap) (ap2) = (ap)
74 #define va_end(ap)
76 #endif /* __GNUC__ */
78 #endif /* _STDARG_H */