While we're on the topic of C's arithmetic deficiencies, how about if
we also add a macro for safe and portable comparison?

Something like "ARITH_COMPARE (A, OP, B)" to compare A and B
numerically rather than using C's rules.  So, for example,
ARITH_COMPARE (-1, <, sizeof "x") would return true even though
typically (-1 > sizeof "x") in C, and
ARITH_COMPARE ((float) LONG_MAX, <, LONG_MAX) even though typically
(float) LONG_MAX == LONGMAX in C.

I initially thought of two macros, INT_COMPARE and FLOAT_COMPARE, but
it might be nice to have just one macro ARITH_COMPARE that can do the
job of either: that way, if you're using some random arithmetic type
defined by the system, you won't have to worry whether it's floating
point.

This new macro could be in a new arith-compare module, or perhaps
we could stretch things a bit and put it into intprops, as all of
the deficiencies it's correcting are related to integers.

Reply via email to