This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Calling va_start multiple times vs __va_copy
- To: Sebastian Ude <ude at handshake dot de>
- Subject: Re: Calling va_start multiple times vs __va_copy
- From: Carlo Wood <carlo at alinoe dot com>
- Date: Wed, 8 Aug 2001 19:27:22 +0200
- Cc: gcc at gcc dot gnu dot org
- References: <20010808113530.1903896D4B@sender.ngi.de>
On Wed, Aug 08, 2001 at 01:38:05PM +0200, Sebastian Ude wrote:
>
> Is it legitime to parse the optional arguments in a variadic function
> multiple times _without_ copying the va_list through (__)va_copy ?
>
> I mean a situation like this one:
>
> void foo( int argno, ... )
> {
> va_list ap;
>
> va_start(ap, argno);
> /* parse arguments through va_arg */
> va_end(ap);
>
> va_start(ap, argno);
> /* parse arguments again */
> va_end(ap);
> }
>
> With GCC, that works - but is that against the standards ?
It will work with almost all OS, but there is at least one
that I know of where va_list is not a struct but a pointer to
a struct. In the latter case it doesn't work.
You could test for the need to use va_copy by testing if
it is a struct. I wrote the following test for 'ircu'
(http://ircu.sourceforge.net/):
dnl
dnl Macro: ircu_VA_LIST
dnl
dnl Check if va_list is a struct or an array/pointer.
dnl
AC_DEFUN(ircu_VA_LIST,
[dnl Check if va_list is a struct or an array/pointer.
AC_CACHE_CHECK([if va_list is a struct], ircu_cv_sys_va_list_is_struct,
[AC_TRY_RUN([#include <stdarg.h>
void vtest(va_list vl)
{
va_arg(vl, int);
}
int test(int ret, ...)
{
va_list vl;
va_start(vl, ret);
vtest(vl);
ret = va_arg(vl, int);
va_end(vl);
return ret;
}
int main(void)
{
exit(test(0, 0, 1));
}], ircu_cv_sys_va_list_is_struct=yes, ircu_cv_sys_va_list_is_struct=no)])
if test $ircu_cv_sys_va_list_is_struct = yes; then
AC_DEFINE(VA_LIST_IS_STRUCT)
fi])
This test assumes the current language is C.
--
Carlo Wood <carlo@alinoe.com>