va_list q
Marcel Moolenaar
marcel at xcllnt.net
Wed Apr 21 09:53:08 PDT 2004
On Wed, Apr 21, 2004 at 06:51:27PM +0300, Valentin Nechayev wrote:
>
> cc -O -pipe -g -I../include -DHAVE_PATHS_H -D_BITYPES -c utils.c
> utils.c: In function `vslprintf':
> utils.c:253: error: invalid use of non-lvalue array
> *** Error code 1
>
> The code in question is:
>
> int
> vslprintf(buf, buflen, fmt, args)
> [...]
> #ifndef __powerpc__
> > n = vslprintf(buf, buflen + 1, f, va_arg(args, va_list));
> #else
> /* On the powerpc, a va_list is an array of 1 structure */
> n = vslprintf(buf, buflen + 1, f, va_arg(args, void *));
> #endif
>
> (I selected failed line with '>')
>
> va_arg() uses translation to pointer to specified type; this translation
> fails with message shown above. Can anybody say how can it be fixed,
> and whether shown powerpc hack is applicable to ia64 if it's good solution?
The use of va_arg(args, va_list) works on ia64 (FreeBSD, HP-UX and Linux).
Given the limited context, I can only suggest that you try to create a
temporary variable of type va_list and change the offending line to:
va_list tmpvalist = va_arg(args, va_list);
n = vslprintf(buf, buflen + 1, f, tmpvalist);
This may make the compiler happy by giving it more type awareness.
Attached a simple testcase that va_arg(ap, va_list) works.
--
Marcel Moolenaar USPA: A-39004 marcel at xcllnt.net
-------------- next part --------------
#include <stdarg.h>
#include <stdio.h>
int
vf2(int count, va_list ap)
{
va_list val;
int i, n;
printf("%d ->", count);
val = va_arg(ap, va_list);
for (i = 0; i < count; i++) {
n = va_arg(val, int);
printf(" %d", n);
}
printf("\n");
return (0);
}
int
f2(int count, ...)
{
va_list ap;
int ret;
va_start(ap, count);
ret = vf2(count, ap);
va_end(ap);
return (ret);
}
int
vf1(int count, va_list ap)
{
return (f2(count, ap));
}
int
f1(int count, ...)
{
va_list ap;
int ret;
va_start(ap, count);
ret = vf1(count, ap);
va_end(ap);
return (ret);
}
int
main()
{
return (f1(3, 1, 2, 3));
}
More information about the freebsd-ia64
mailing list