On Mon, Apr 20, 2015 at 12:03:11PM +0100, Kyrill Tkachov wrote: > The definition and comment on IN_RANGE in system.h is: > /* A macro to determine whether a VALUE lies inclusively within a > certain range without evaluating the VALUE more than once. This > macro won't warn if the VALUE is unsigned and the LOWER bound is > zero, as it would e.g. with "VALUE >= 0 && ...". Note the LOWER > bound *is* evaluated twice, and LOWER must not be greater than > UPPER. However the bounds themselves can be either positive or > negative. */ > #define IN_RANGE(VALUE, LOWER, UPPER) \ > ((unsigned HOST_WIDE_INT) (VALUE) - (unsigned HOST_WIDE_INT) (LOWER) \ > <= (unsigned HOST_WIDE_INT) (UPPER) - (unsigned HOST_WIDE_INT) (LOWER)) > > Since it works on positive or negative bounds, I'd think it would work on > signed numbers, wouldn't it?
Of course it does, as long as the types of VALUE, LOWER and UPPER aren't wider integer types than {,un}signed HOST_WIDE_INT. As HWI is always 64-bit now, that just means it wouldn't work for 128-bit integral types that aren't used anywhere in GCC. So, just don't use IN_RANGE for floating point values, that might have surprising effects, otherwise it is safe to use it. Jakub