Candice has inherited some legacy C++ code. It's legacy enough, for example, that there are about 15 definitions of a boolean, depending which headers you include. It contains, in Candice's words, "an ambitious attempt to #undef return".
In short, there are plenty of horrors in the code. But this particular short snippet is the one that drew Candice's attention.
#define NEGATE_VALUE(x) ( -1 * x )
If only there were some convenient symbol or operator that allowed us to negate a numeric value. Some way we could take, say, a
1, and make it negative, maybe by putting a
- in front of it, e.g.,
-1. And maybe that could also work with variables, so we could write
-x to represent the negation of
The macro isn't wrong, it's just useless in a way that makes me puzzle about what the underlying motivation was. I can't understand why someone would write this, and even once it's written, I don't understand why anyone would use this macro. And yet, it was.
This post originally appeared on The Daily WTF.