Article View: comp.std.c
Article #5321Re: Variable length arg lists for macros
From: Wonderly
Date: Fri, 02 Sep 1988 13:57
Date: Fri, 02 Sep 1988 13:57
64 lines
2187 bytes
2187 bytes
From article <1036@cbnews.ATT.COM>, by lvc@cbnews.ATT.COM (Lawrence V. Cipriani):
] In article <438@ucsvc.unimelb.edu.au>, u5565522@ucsvc.unimelb.edu.au (David Clunie) writes:
]
] ....
]
]> 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");)
] }
I always use the following
#ifdef DEBUG
#define debug(x,y) {if (x > debuglvl) printf y};
#else DEBUG
#define debug(x,y)
#endif DEBUG
This gets you something like the above, although it does not allow
arbitrary values or conditions to govern the printing or execution
of debug information/code. In general though I seldom need other
conditions to govern the debug output because I try to check all of
the conditions where things might go wrong anyway so I would write
the above as...
c(i)
{
if (i == 0) {
debug (1, ("OOOPS i == %d\n", i));
abort();
}
}
Gregg Wonderly
AT&T Bell Laboratories DOMAIN: gregg@ihlpb.att.com
IH2D217 - (312) 979-2794 UUCP: ihnp4!ihlpb!gregg
--
Gregg Wonderly
AT&T Bell Laboratories DOMAIN: gregg@ihlpb.att.com
IH2D217 - (312) 979-2794 UUCP: ihnp4!ihlpb!gregg
Technical Details
Message-ID:
<8671@ihlpb.ATT.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!attcan!uunet!lll-winken!lll-tis!ames!killer!osu-cis!att!ihlpb!greggReferences:
<1036@cbnews.ATT.COM>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!attcan!uunet!lll-winken!lll-tis!ames!killer!osu-cis!att!ihlpb!gregg From: gregg@ihlpb.ATT.COM (Wonderly) Newsgroups: comp.std.c Subject: Re: Variable length arg lists for macros Message-ID: <8671@ihlpb.ATT.COM> Date: 2 Sep 88 13:57:20 GMT References: <1036@cbnews.ATT.COM> Organization: AT&T Bell Laboratories - Naperville, Illinois Lines: 63