Passing Variable Numbers of Arguments

Dave Corcoran dave at aspect.UUCP
Thu Feb 14 13:10:13 AEST 1991


In article <5196 at media-lab.MEDIA.MIT.EDU>, dyoung at media-lab.MEDIA.MIT.EDU (David Young) writes:
> 
> What I'd like is something that could transform a call like:
> 
>      PringMsg( window, formatString, <formatArgs>)
> 
> into the following chunk of code:
> 
>      { 
>        sprintf( globalFoo, formatString, <formatArgs>);
>        BlahBlah( window, globalFoo);
>      }
> 

run this through m4
--------------------8<--------------------------
define(PringMsg,`
     { 
       sprintf(globalFoo, $2, shift(shift($*)));
       BlahBlah($1, globalFoo);
     }')

PringMsg( window, formatString, f,o,rm,at,Ar,gs)
PringMsg( window, formatString, form,at,Args)
--------------------8<--------------------------

CAVEAT: you cannot have commas in formatString
-- 
David Corcoran		      -@@
uunet!aspect!dave	        ~
In a society where anything goes eventually everything will.



More information about the Comp.lang.c mailing list