by bluedino · 11y ago · 0 comments
The previous commenter may have entered that into say, a Python console where it wouldn't exhibit that behavior.
So what then is the CORRECT way of doing this comparison in C, avoiding potential overflow pitfalls?
return (x > y) - (x < y);For many data types, like time, that will normally never happen, making subtraction the safest no-brainpower-needed approach. If in doubt, use the next larger integer type.
return (x > y) - (x < y);
Quick. What's that do?What will the next person who looks at the code think it does?
Duh.