Can I use a terinary operator in a define as oppose to using an if?
Suppose I have a macro defined, and I am using that macro within an if
else statement
#define LOG(X) if (some_condition) dosomething();
if (somebool)
LOG(X)
else
somethingelse();
Now this is a tricky case, I realized that depending on the indentation
there might be some ambiguity about which 'if' the 'else' should go with.
I have came up with this soultion
(some_condition) ? dosomething() : true;
This solves the problem, but I am not sure what the repercussion of having
a true statement are. Is this a good solution, or is there a better
approach?
No comments:
Post a Comment