[PATCH 1/2] PR77822
Segher Boessenkool
segher@kernel.crashing.org
Fri Nov 18 14:02:00 GMT 2016
On Fri, Nov 18, 2016 at 01:09:24PM +0100, Dominik Vogt wrote:
> How about this:
>
> --
> /* A convenience macro to determine whether a SIZE lies inclusively
> within [1, UPPER], POS lies inclusively within between
> [0, UPPER - 1] and the sum lies inclusively within [1, UPPER].
> UPPER must be >= 1. */
> #define SIZE_POS_IN_RANGE(SIZE, POS, UPPER) \
> (IN_RANGE ((POS), 0, (unsigned HOST_WIDE_INT) (UPPER) - 1) \
> && IN_RANGE ((SIZE), 1, (unsigned HOST_WIDE_INT) (UPPER) \
> - (unsigned HOST_WIDE_INT)(POS)))
^ missing space here
> IN_RANGE(POS...) makes sure that POS is a non-negative number
> smaller than UPPER, so (UPPER) - (POS) does not wrap. Or is there
> some case that the new macro does not handle?
I think it works fine.
With a name like UPPER, you may want to have SIZE_POS_IN_RANGE work like
IN_RANGE, i.e. UPPER is inclusive then. Dunno.
Segher
More information about the Gcc-patches
mailing list