Using Macros

Karl Heuer karl at haddock.ima.isc.com
Thu Aug 9 08:55:06 AEST 1990


In article <5439 at stpstn.UUCP> lerman at stpstn.UUCP (Ken Lerman) writes:
>IMHO the many responders to this question gave the right answer to
>perhaps the wrong question.  The issues is not how to write the macro,
>but how to invoke it.  [Put braces around it.]

Your solution needs to be done at each invocation, whereas the other responses
fix the problem at the source.  In the best case (when the macro can be
written as an expression that evaluates each argument exactly once), the user
doesn't even need to know it's a macro.  This is a plus.

>Aside:
>	The one that really gets me is when someone does:
>	foo(gag) and you later discover that foo() is a macro.
>	Unfortunately, ANSI C has some of these.  Is there a
>	requirement that they are expressions?

With very few exceptions%, any functions that the vendor chooses to implement
as macros must have the property described above.

Karl W. Z. Heuer (karl at kelp.ima.isc.com or ima!kelp!karl), The Walking Lint
________
% assert() must under-evaluate when NDEBUG is set.  getc() and putc() may
  over-evaluate the stream argument.  I can't think of any others.



More information about the Comp.lang.c mailing list