![Quote](https://cboard.cprogramming.com/images/misc/quote_icon.png)
Originally Posted by
RichSelian
I want such a macro in my project: cmp(x, y) returns a positive number when x > y, a negative number when x < y, and 0 when x == y. of course I know the simplest way:
Code:
#define cmp(x, y) (((x) > (y)) ? 1 : (((x) == (y)) ? 0 : -1))
but this cannot work properly for the code like cmp(x++, y++). Can this limit be fixed?
Do you really care if it returns 1, 0 or -1? If all you care about is a positve, 0 or negative value you can simply return (x - y);
Code:
#define cmp(x, y) (x - y)