Skip to content
Prev 165247 / 398506 Next

understanding lexical scope

Peter Dalgaard wrote:
using c macros, you end up with g(y) substituted by 2*y+2, rather than
y+2*2, as you say (and rather than 2*(y+2), which you'd effectively get
using a function).

that's why you'd typically include all occurences of all macro
'parameters' in the macro 'body' in parentheses:

#define f(x) 2*(x)

some consider using c macros as not-so-good practice and favour inline
functions.  but macros are not always bad; in scheme, for example, you
have a hygienic macro system which let's you use the benefits of macros
while avoiding some of the risks.

vQ