#ifndef _STDARG_H
#define _STDARG_H

typedef char *va_list;		// va_list һַָ͡

/* Amount of space required in an argument list for an arg of type TYPE.
TYPE may alternatively be an expression whose type is used. */
/* ΪTYPE arg бҪĿռ
TYPE Ҳʹø͵һʽ */

// 䶨ȡTYPE ͵ֽڳֵint (4)ı
#define __va_rounded_size(TYPE) \
(((sizeof (TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int))

// úʵ֣ʹAP ָ򴫸Ŀɱĵһ
// ڵһεva_arg va_end ֮ǰȵøú
// 17 ϵ__builtin_saveregs()gcc Ŀlibgcc2.c жģڱĴ
// ˵ɲμgcc ֲ½ڡTarget Description Macrosе
// Implementing the Varargs MacrosСڡ
#ifndef __sparc__
#define va_start(AP, LASTARG) \
(AP = ((char *) &(LASTARG) + __va_rounded_size (LASTARG)))
#else
#define va_start(AP, LASTARG) \
(__builtin_saveregs (), \
AP = ((char *) &(LASTARG) + __va_rounded_size (LASTARG)))
#endif

// úڱúһءva_end ޸AP ʹµ
// va_start ֮ǰܱʹáva_end va_arg еĲٱá
void va_end (va_list);		/* Defined in gnulib *//* gnulib ж */
#define va_end(AP)

// úչʽʹһݲͬͺֵ
// ȱʡֵva_arg ַ޷ַ͸͡
// ڵһʹva_arg ʱرеĵһÿεöرе
// һͨȷAPȻָһʵֵġ
// va_arg ʹTYPE ɷʺͶλһÿһva_arg޸AP ָʾ
// еһ
#define va_arg(AP, TYPE) \
(AP += __va_rounded_size (TYPE), \
*((TYPE *) (AP - __va_rounded_size (TYPE))))

#endif /* _STDARG_H */
