Variable arg function question

Roland Smith rsmith at xs4all.nl
Sun May 4 15:47:37 UTC 2008


On Sun, May 04, 2008 at 08:34:30AM -0700, Unga wrote:
> 
> --- Roland Smith <rsmith at xs4all.nl> wrote:
> 
> > On Sun, May 04, 2008 at 07:02:36AM -0700, Patrick
> > Clochesy wrote:
> > > 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.
> > 
> > That's a good idea. If one uses __VA_ARGS__ instead
> > of __VARARGS__, it
> > should work with any C99 compliant compiler,
> > including gcc.

> I gave it a try, but I cannot get it to work:
> (As per above wikipedia example)
> 
> void realdprintf (char const *file, int line, char
> const *fmt, ...); 
> #define dprintf(...) realdprintf(__FILE__, __LINE__,
> __VA_ARGS__)
> 
> To solve my problem, I must be able to indicate the
> end of the arg list, may be by a empty string (""),
> but GNU C compiler does not allow to specify anything
> after the ... .

Try something like what Patrick suggested:

#define f(...) _f(__VA_ARGS__,NULL)

Roland
-- 
R.F.Smith                                   http://www.xs4all.nl/~rsmith/
[plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated]
pgp: 1A2B 477F 9970 BA3C 2914  B7CE 1277 EFB0 C321 A725 (KeyID: C321A725)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20080504/84c7fb18/attachment.pgp


More information about the freebsd-questions mailing list