Fix va_arg() problem when adjusting argument pointer when a structure is

passed which is larger than an int but has int alignment.  As well as
fixing the described problem, this is the same way it is handled in the
Irix and Ultrix header files.

Problem and suggested solution by Uros Prestor in port-mips mailling
list.
This commit is contained in:
simonb 2001-08-17 07:15:16 +00:00
parent 8d6595d978
commit b2b2f7ccfa
1 changed files with 8 additions and 4 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: stdarg.h,v 1.19 2000/02/19 09:23:44 mycroft Exp $ */
/* $NetBSD: stdarg.h,v 1.20 2001/08/17 07:15:16 simonb Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -41,6 +41,10 @@
#include <machine/ansi.h>
#include <sys/featuretest.h>
#if defined(_MIPS_BSD_API) && _MIPS_BSD_API != _MIPS_BSD_API_LP32
#error stdargs.h does not work with 64 bit ABIs
#endif
typedef _BSD_VA_LIST_ va_list;
#ifdef __lint__
@ -53,15 +57,15 @@ typedef _BSD_VA_LIST_ va_list;
#if BYTE_ORDER == LITTLE_ENDIAN
#define va_arg(ap, T) \
(((T *)( \
(ap) += (/*CONSTCOND*/ sizeof(T) <= sizeof(int) \
(ap) += (/*CONSTCOND*/ __alignof__(T) <= sizeof(int) \
? sizeof(int) : ((long)(ap) & 4) + sizeof(T)), \
(ap) - (/*CONSTCOND*/ sizeof(T) <= sizeof(int) \
(ap) - (/*CONSTCOND*/ __alignof__(T) <= sizeof(int) \
? sizeof(int) : sizeof(T)) \
))[0])
#else
#define va_arg(ap, T) \
(((T *)( \
(ap) += (/*CONSTCOND*/ sizeof(T) <= sizeof(int) \
(ap) += (/*CONSTCOND*/ __alignof__(T) <= sizeof(int) \
? sizeof(int) : ((long)(ap) & 4) + sizeof(T)) \
))[-1])
#endif