1 /* ----------------------------------------------------------------------------
3 * ----------------------------------------------------------------------------
4 * Public Domain C Library - http://pdclib.sourceforge.net
5 * This code is Public Domain. Use, modify, and redistribute at will.
6 * ----------------------------------------------------------------------------
8 * ----------------------------------------------------------------------------
9 * This header is part of a freestanding implementation
10 * --------------------------------------------------------------------------*/
13 #define _STDARG_H _STDARG_H
15 /* TODO: This code was contributed by Michael Moody, who added:
16 * "As always with my code it's not guaranteed bug-free (In fact I know for a
17 * fact it won't work properly on certain archs)."
19 * - arguments are passed on the stack;
20 * - arguments are alligned to pointer size.
23 /* ----------------------------------------------------------------------------
25 * --------------------------------------------------------------------------*/
27 typedef char * va_list;
29 /* ----------------------------------------------------------------------------
31 * --------------------------------------------------------------------------*/
33 /** Returns the size of 'type' rounded up to the nearest multiple of the size
34 * of a pointer. This macro is just here for clarity.
36 #define __va_round(type) \
38 (sizeof(type) + sizeof(void *) - 1) & ~(sizeof(void *) - 1) \
41 /** Initialises ap for use by va_arg by setting ap to point at the first
42 * argument in the ellipsis. parmN is the last known parameter in the function
43 * definition (ie the one before the ellipsis).
45 #define va_start(ap, parmN) \
47 (ap) = (char *)&parmN + (__va_round(parmN)) \
52 /** Returns the next argument, assumed variable type is 'type', in the
55 #define va_arg(ap, type) \
57 (ap) += (__va_round(type)) \
59 (*(type*)((ap) - (__va_round(type)))) \
71 /** Makes the va_list dest be a copy of the va_list src.
73 #define va_copy(dest, src) \
80 #endif /* _STDARG_H */