Xref: utzoo comp.unix.wizards:8395 comp.lang.c:10082
Path: utzoo!attcan!uunet!husc6!tut.cis.ohio-state.edu!lvc
From: lvc@tut.cis.ohio-state.edu (Lawrence V. Cipriani)
Newsgroups: comp.unix.wizards,comp.lang.c
Subject: Re: #defines with variable # arguments
Summary: use double parens
Message-ID: <13091@tut.cis.ohio-state.edu>
Date: 12 May 88 05:11:30 GMT
References: <2855@phoenix.Princeton.EDU>
Distribution: na
Organization: Ohio State Computer & Info Science
Lines: 26

In article <2855@phoenix.Princeton.EDU>, lgy@pupthy2.PRINCETON.EDU (Larry Yaffe) writes:
> 
>     Are there any versions of cpp which allow one to define macros which
> accept variable numbers of arguments?  I keep wishing for this every time
> I try to move code developed using sysV sprintf to a BSD system, so that
> I could do something like:
>	examples deleted

This question comes up now and then.  No version of cpp I know has a
variable count capability, but those are only AT&T cpp's.  You can
work around it though, so this is portable.  Define a macro like this:

#define SPRINTF(args)	sprintf args

and use it like this:

	SPRINTF((str, format, a1, a2, ..., an));

The double parens trick cpp into seeing only one argument.  After
cpp expansion you get:

	sprintf (str, format, a1, a2, ..., an);
-- 
Larry Cipriani, AT&T Network Systems and Ohio State University
Domain: lvc@tut.cis.ohio-state.edu
Path: ...!cbosgd!osu-cis!tut.cis.ohio-state.edu!lvc (weird but right)