🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #5318

Re: Variable length arg lists for macros

#5318
From: Lawrence V. Cipriani
Date: Thu, 01 Sep 1988 12:19
39 lines
1539 bytes
In article <438@ucsvc.unimelb.edu.au>, u5565522@ucsvc.unimelb.edu.au (David Clunie) writes:
> How do people feel about the idea of preprocessor macros with variable
> length argument lists ?
I'd like it, but its not essential.  I don't mind using double parenthesis
to fake out the preprocessor.

> However this can not be done with macro calls. Wouldn't it be nice to be
> able to do something like ...
> 
> 	#ifdef TRACE
> 	#define	tracef(s,...)	printf(s,...)
> 	#else
> 	#define	tracef(s,...)	/* nothing */
> 	#endif
> 
> At present, this CANNOT BE DONE, without nesting parentheses (clumsy) or
> using a call to an empty function (inefficient, unless you have inline
> integration in an optimizing compiler).

Only clumsy for the uncoordinated :-)  You missed one more way:

	#ifdef TRACE
	#define trace(anything)	anything
	#else
	#define trace(anything)
	#endif

and you use it like this:

	c(i)
	{
		trace( if (i == 0) printf("boom\n");)
	}

The only restriction I can think of now is that you'll have to be careful
how the comma operator is used.

-- 
Larry Cipriani, AT&T Network Systems, Columbus OH, cbnews!lvc lvc@cbnews.ATT.COM
Technical Details
Message-ID: <1036@cbnews.ATT.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!cbnews!lvc
References: <438@ucsvc.unimelb.edu.au>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!cbnews!lvc
From: lvc@cbnews.ATT.COM (Lawrence V. Cipriani)
Newsgroups: comp.std.c
Subject: Re: Variable length arg lists for macros
Summary: ho hum
Message-ID: <1036@cbnews.ATT.COM>
Date: 1 Sep 88 12:19:44 GMT
References: <438@ucsvc.unimelb.edu.au>
Organization: AT&T Bell Laboratories, Columbus
Lines: 39