Article View: comp.std.c
Article #51Re: macros: "same name/different number of arguments"
From: Norman Diamond
Date: Mon, 02 Nov 1992 05:04
Date: Mon, 02 Nov 1992 05:04
54 lines
2938 bytes
2938 bytes
Apologies if you see this twice. I don't think this escaped from Digital before, and I can no longer abuse Berkeley's daemon to get things posted. In article <1992Oct30.103610.24927@olymp.informatik.uni-bonn.de> hermann@uran.informatik.uni-bonn.de (Hermann Stamm) writes: > Define a macro which expands to a function-call > with one open bracket but without the closing one. > This "allows" a variable number of arguments; A variable number of C expressions as arguments to the C function, not a variable number of macro arguments. A devious user would be able to insert other stuff as well, though of course that only affects herself and the poor readers who will have to maintain her program later. > the only disadvantage is, that you have to write one > more closing than opening bracket in the program. You could define a second macro to generate the closing parenthesis. > - Is this portable/ANSI-conform ? If done properly, yes. Each parenthesis (and each bracket and each brace) stands alone as a token, not like the apostrophese and quotation marks that delimit character and string constants. > - Are there any reasons for not doing it this way (style, ...) ? Followups to this question should be directed to alt.religion.computers. > - What is the better method if more than one argument is the same for > all function-calls (the X and L in the below example), the one > used for CONTRACT or the one used for EXPAND ? If you're sure it will always be the same, then just hard-code it in the macro expansions, instead of making it a macro argument. >The main reason for not using the variable number of arguments operator >,... of functions is the loosing of type-checking in the variable >positions; here type-checking is done at each position! Huh? Macro arguments are never type-checked. >contract(circle C, int l) ==> contract circle C's > radius by length l. > >contact(rectangle R, int lx, int ly) ==> contract rectangle R's > width by lx and its > height by ly. Huh? I thought we were talking about C. If you want a C++ answer, go ask in that group. -- Norman Diamond diamond@jit081.enet.dec.com If this were the company's opinion, I wouldn't be allowed to post it. "It's been a lovely recession."
Technical Details
Message-ID:
<1992Nov2.050456.19065@nntpd.lkg.dec.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!elroy.jpl.nasa.gov!decwrl!pa.dec.com!nntpd2.cxo.dec.com!nntpd.lkg.dec.com!jit345.bad.jit.dec.com!diamondReferences:
<1992Oct30.103610.24927@olymp.informatik.uni-bonn.de>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!sparky!uunet!elroy.jpl.nasa.gov!decwrl!pa.dec.com!nntpd2.cxo.dec.com!nntpd.lkg.dec.com!jit345.bad.jit.dec.com!diamond From: diamond@jit345.bad.jit.dec.com (Norman Diamond) Subject: Re: macros: "same name/different number of arguments" Message-ID: <1992Nov2.050456.19065@nntpd.lkg.dec.com> Sender: usenet@nntpd.lkg.dec.com (USENET News System) Reply-To: diamond@jit.dec.com (Norman Diamond) Organization: Digital Equipment Corporation Japan , Tokyo References: <1992Oct30.103610.24927@olymp.informatik.uni-bonn.de> Date: Mon, 2 Nov 1992 05:04:56 GMT Lines: 54