tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: KNF and the C preprocessor



On Mon, Dec 10, 2012 at 05:58:02PM +0000, Paul_Koning%Dell.com@localhost wrote:
 > > (Also, as a side issue, at least one of your examples is invalid.
 > > 
 > >> 1 Lazy evaluation: unlike a function call's arguments, a macro's
 > >>  arguments are not evaluated before the macro is "called."  E.g., in
 > >>  the code below, the second and following arguments of M(a, b, c, d, e)
 > >>  are not evaluated unless p(a) is true:
 > >> 
 > >>   #define M(__x, ...)                     \
 > >>   do {                                    \
 > >>           if (p(__x))                     \
 > >>                   f(__x, __VA_ARGS__);    \
 > >>   } while (false)
 > >> 
 > >>   M(a, b, c, d, e);
 > > 
 > > The C standard makes no such guarantee.)
 > 
 > Really?  if (false) foo (bar()); might evaluate bar() ?  Where does
 > it say that?

Sorry, I meant the part "a macro's arguments are not evaluated before
the macro is "called". The compiler is free to rearrange things
(including across sequence points) based on things it can prove about
the C abstract machine, which as we know doesn't take into account
various things found in real life.

However, I guess my real objection is that this doesn't constitute
lazy evaluation.

-- 
David A. Holland
dholland%netbsd.org@localhost


Home | Main Index | Thread Index | Old Index