In a previous question what I thought was a good answer was voted down for the suggested use of macros
#define radian2degree(a) (a * 57.295779513082)
#define degree2radian(a) (a * 0.017453292519)
instead of inline functions. Please excuse the newbie question, but what is so evil about macros in this case?
There’s a couple of strictly evil things about macros.
They’re text processing, and aren’t scoped. If you
#define foo 1, then any subsequent use offooas an identifier will fail. This can lead to odd compilation errors and hard-to-find runtime bugs.They don’t take arguments in the normal sense. You can write a function that will take two
intvalues and return the maximum, because the arguments will be evaluated once and the values used thereafter. You can’t write a macro to do that, because it will evaluate at least one argument twice, and fail with something likemax(x++, --y).There’s also common pitfalls. It’s hard to get multiple statements right in them, and they require a lot of possibly superfluous parentheses.
In your case, you need parentheses:
needs to be
and you’re still stepping on anybody who writes a function
radian2degreein some inner scope, confident that that definition will work in its own scope.