Why is the ternary operator used to define 1 and 0 in a macro?
You are correct, in C it is tautologous. Both your particular ternary conditional and (1 > 0)
are of type int
.
But it would matter in C++ though, in some curious corner cases (e.g. as parameters to overloaded functions), since your ternary conditional expression is of type int
, whereas (1 > 0)
is of type bool
.
My guess is that the author has put some thought into this, with an eye to preserving C++ compatibility.
There are linting tools that are of the opinion that the result of a comparison is boolean, and can't be used directly in arithmetic.
Not to name names or point any fingers, but PC-lint is such a linting tool.
I'm not saying they're right, but it's a possible explanation to why the code was written like that.