C macro gotcha
Argh - I fell for the obvious C macro gotcha. I had a macro like this:
#define FOO(x) do_something(); do_something_else()
but I was calling it like this:
if (some_condition) FOO(x);
This is bad! It is equivalent to this:
if (some_condition) do_something();
do_something_else();
So do_something_else()
always gets called. Oops!
Normally I write my macros in the recommended way:
#define FOO(x) do { do_something(); do_something_else(); } while (0)
Not feeling particularly smart today. Hmm.