[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Negative table index
- From: Tom N Harris <telliamed@...>
- Date: Tue, 23 Dec 2014 14:11:33 -0500
On Tuesday, December 23, 2014 09:14:59 AM Roberto Ierusalimschy wrote:
> A good compiler can throw away the test 't+n>=t': It knows that 'n'
> is non negative, because of a previous 'if e >= f', and it can assume
> that signed arithmetic operations do not overflow (as overflows have
> undefined behavior in the standard).
>
> (Your code also has a problem when 'n' is maxinteger, because then the
> for loop will never end.)
Overflow of signed integers remains my least favorite part of C. A reason to
abhor undefined behavior. Which is why I'm nervous about the state of negative
indexes in table library functions.
Anyway, since there won't be negative overflow the check is still just
INT_MAX - t < e - f. Unless there is some reason other than overflow of t that
needs to be considered.
--
tom <telliamed@whoopdedo.org>