|
|
|
|
|
by mschaef
3386 days ago
|
|
> a certain C macro might evaluate some expression twice. Everyone knows that this is dangerous...ISO C itself says that getc may evaluate its argument multiple times; ... Lisp macros do not have issues that are unfixable in this way. If your macros is 'fixed' to emulate function call semantics by evaluating its arguments only once, then maybe a function is a more appropriate abstraction in the first place. The whole point of macros is that they let you break the rules of function call application in hopefully useful and predictable ways. Another way to look at it is that repeatedly evaluating an argument is what you do NOT want for a macro like 'getc', but probably what you DO want for a macro like 'repeat'. The danger lies in the fact that it's hard to tell the difference when looking at a call site in isolation. Whether or not that danger is an acceptable risk is, of course, situation dependent. |
|
All the programmer has to do is achieve run-time coverage to catch all the problems.
We could define a getc-like macro such that getc(*stream++) would diagnose, provided that the line is executed.
See sfx.h and sfx.c here: http://git.savannah.nongnu.org/cgit/kazlib.git/tree/