This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: va_arg *, and why not.
- To: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Subject: Re: va_arg *, and why not.
- From: Franz Sirl <Franz dot Sirl-kernel at lauterbach dot com>
- Date: Mon, 17 Jul 2000 16:53:06 +0200
- Cc: gdr at codesourcery dot com,mark at codesourcery dot com,gcc-bugs at gcc dot gnu dot org,geoffk at cygnus dot com
At 16:14 17.07.00, Kaveh R. Ghazi wrote:
> > From: Mark Mitchell <mark@codesourcery.com>
> >
> > >>>>> "Gabriel" == Gabriel Dos Reis <gdr@codesourcery.com> writes:
> >
> > Gabriel> Hmm, I'm confused there. I was under the impression that
> > Gabriel> it was taking the address of a va_list function argument
> > Gabriel> that was not portable. Furthermore, in his proposed
> > Gabriel> resolution using va_copy was one option.
> >
> > But with the caveat that there be a libiberty/system.h equivalent to
> > handle systems that do not define va_copy.
>
>
>FYI, system.h already defines a backup va_copy. I don't know if it's
>*correct*, but it does exist. You may wish to verify it DTRT.
No, it is not correct in system.h. It should look like this:
#ifdef HAVE_VA_LIST_AS_ARRAY
#define va_copy(d,s) (*(d) = *(s))
#else
#define va_copy(d,s) ((d) = (s))
#endif
This is the autoconf test that mozilla uses:
dnl Does this platform require array notation to assign to a va_list?
dnl If cross-compiling, we assume va_list is "normal". If this breaks
dnl you, set ac_cv_valistisarray=true and maybe define HAVE_VA_LIST_AS_ARRAY
dnl also just to be sure.
AC_MSG_CHECKING(whether va_list assignments need array notation)
AC_CACHE_VAL(ac_cv_valistisarray,
[AC_TRY_RUN([#include <stdlib.h>
#include <stdarg.h>
void foo(int i, ...) {
va_list ap1, ap2;
va_start(ap1, i);
ap2 = ap1;
if (va_arg(ap2, int) != 123 || va_arg(ap1, int) !=
123) { exit(1); }
va_end(ap1); va_end(ap2);
}
int main() { foo(0, 123); return(0); }],
[ac_cv_valistisarray=false],
[ac_cv_valistisarray=true],
[ac_cv_valistisarray=false])])
if test "$ac_cv_valistisarray" = true ; then
AC_DEFINE(HAVE_VA_LIST_AS_ARRAY)
AC_MSG_RESULT(yes)
else
AC_MSG_RESULT(no)
fi
Franz.