Date: Wed, 21 Apr 2004 09:53:07 -0700 From: Marcel Moolenaar <marcel@xcllnt.net> To: Valentin Nechayev <netch@lucky.net> Cc: ia64@freebsd.org Subject: Re: va_list q Message-ID: <20040421165307.GB832@ns1.xcllnt.net> In-Reply-To: <20040421155127.GS57650@netch.kiev.ua> References: <20040421155127.GS57650@netch.kiev.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
--n8g4imXOkfNTN/H1 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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@xcllnt.net --n8g4imXOkfNTN/H1 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="arg.c" #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)); } --n8g4imXOkfNTN/H1--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040421165307.GB832>