Article View: comp.std.c
Article #5326Re: Variable length arg lists for macros
From: Brian Westley
Date: Tue, 06 Sep 1988 02:34
Date: Tue, 06 Sep 1988 02:34
34 lines
1095 bytes
1095 bytes
There is a way to do this, but it's ugly, dangerous,
noisy, and not portable...
short _NARGS_;
#define max(a,b,c,d,e) \
(_NARGS_=5,-a-_NARGS_,-b-_NARGS_,-c-_NARGS_,-d-_NARGS_,-e-_NARGS_,\
_max(_NARGS_,a-0,b-0,c-0,d-0,e-0))
main()
{
int x,y;
printf("%d ",max(3,5,4));
x = max((-9),(-11),2*6-55);
y = max(4,2-x,(-6),999,5-9);
printf("%d %d %d\n",x,y,max(x,y-3));
}
_max(n,a,b,c,d,e)
int n;
int a,b,c,d,e;
{
int result;
result = a;
if (--n>0 && b>result) result=b;
if (--n>0 && c>result) result=c;
if (--n>0 && d>result) result=d;
if (--n>0 && e>result) result=e;
return result;
}
----
Merlyn LeRoy
Technical Details
Message-ID:
<436@rose3.rosemount.com>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!husc6!mailrus!ames!amdahl!ems!rosevax!rose3!merlynReferences:
<438@ucsvc.unimelb.edu.au> <155@tekn01.chalmers.se>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!husc6!mailrus!ames!amdahl!ems!rosevax!rose3!merlyn From: merlyn@rose3.rosemount.com (Brian Westley) Newsgroups: comp.std.c Subject: Re: Variable length arg lists for macros Message-ID: <436@rose3.rosemount.com> Date: 6 Sep 88 02:34:53 GMT References: <438@ucsvc.unimelb.edu.au> <155@tekn01.chalmers.se> Reply-To: merlyn@rose4.UUCP (Brian Westley) Organization: Rosemount Inc., Burnsville, MN Lines: 34