3 ms·
That's not aif at all. In fact, you can't even do it for "most cases" in C because you don't know what type expr will evaluate to, but if we could cheat and as
by dreish 17y ago
That's not aif at all. In fact, you can't even do it for "most cases" in C because you don't know what type expr will evaluate to, but if we could cheat and assume it will be an int:
#define aif(expr, code) \
{ \
int it = (expr); \
if (it) \
{ \
code; \
} \
}
But this is still not close because in a Lisp, if is an expression that returns a value. We can't use the ternary operator because then there's no place to declare the "it" variable. You can't have an expression that declares a variable local to that expression in C no matter how hard you try.
And the above lacks the "do {} while (0)" weirdness needed to make a cpp macro behave syntactically roughly like a function.
- psranga 17y agoI agree. My bad. I appreciate the clarificaiton.