Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!mailrus!umix!b-tech!umich!itivax!scs From: scs@itivax.UUCP (Steve C. Simmons) Newsgroups: comp.std.c Subject: Re: Variable length arg lists for macros Summary: an additional warning Message-ID: <228@itivax.UUCP> Date: 6 Sep 88 00:30:20 GMT References: <438@ucsvc.unimelb.edu.au> <1036@cbnews.ATT.COM> Reply-To: scs@itivax.UUCP (Steve C. Simmons) Organization: Industrial Technology Institute, Ann Arbor Lines: 45 In article <1036@cbnews.ATT.COM> lvc@cbnews.ATT.COM (Lawrence V. Cipriani) writes: -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 ? -> -> 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, cbnews!lvc lvc@cbnews.ATT.COM A nice hack, but one additional word of warning -- the disappearing line of code can cause some interesting and obscure bugs. I had one program that worked with the trace code but failed oddly without it. The exact form escapes me, but it was something like . . . if ( x == m ) trace( printf( "the consequences\n) ; ) froob( some function ) ; This produced rather different programs depending on the definition of 'trace'! -- Steve Simmons ...!umix!itivax!vax3!scs Industrial Technology Institute, Ann Arbor, MI. "You can't get here from here."