#defines with variable # arguments
Lawrence V. Cipriani
lvc at tut.cis.ohio-state.edu
Thu May 12 15:11:30 AEST 1988
In article <2855 at phoenix.Princeton.EDU>, lgy at 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 at tut.cis.ohio-state.edu
Path: ...!cbosgd!osu-cis!tut.cis.ohio-state.edu!lvc (weird but right)
More information about the Comp.unix.wizards
mailing list