Date: Sun, 4 May 2008 07:02:36 -0700 From: Patrick Clochesy <pcloches@gmail.com> To: Peter Boosten <peter@boosten.org> Cc: Unga <unga888@yahoo.com>, "freebsd-questions@freebsd.org" <freebsd-questions@freebsd.org> Subject: Re: Variable arg function question Message-ID: <8FF3737F-1292-4A19-8A7D-789D8DD70CBE@gmail.com> In-Reply-To: <481DA10B.30903@boosten.org> References: <336540.36159.qm@web57014.mail.re3.yahoo.com> <481DA10B.30903@boosten.org>
next in thread | previous in thread | raw e-mail | index | archive | help
What about using a macro (...) in front of the function to csll it which passes __VARARGS__, NULL to ensure there is always a trailing NULL? I think this would at least work in GCC... Can' test on my phone though. -Patrick On May 4, 2008, at 4:42 AM, Peter Boosten <peter@boosten.org> wrote: > Unga wrote: >> Hi all >> I need to implement a variable argument function in C. >> The number of args are not known but the type is >> known, all are strings. >> Unfortunately va_arg() [stdarg(3)] does not return >> NULL or any other suitable value after processing the >> arg list, it just simply crashes once the arg list is >> exhausted. >> It seems there is no way to know the number of args >> inside the called function. > > Why is it in your opinion so hard to count the number of arguments > *before* you call the function, in other words, what in your program > prevents this count? > > Peter > -- > http://www.boosten.org > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org > "
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?8FF3737F-1292-4A19-8A7D-789D8DD70CBE>