[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

proposed ARITH_COMPARE macro

From: Paul Eggert
Subject: proposed ARITH_COMPARE macro
Date: Sun, 15 May 2011 09:59:01 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20110424 Thunderbird/3.1.10

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

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

[Prev in Thread] Current Thread [Next in Thread]