Re: Detecting overflows while computing off_t
- From: richard@xxxxxxxxxxxxxxx (Richard Tobin)
- Date: 22 Dec 2006 23:44:16 GMT
In article <slrneoncai.2rv.cheney@xxxxxxxxxxxxxxxx>,
Andre Majorel <cheney@xxxxxxxxxxxxxxx> wrote:
How do you compute an off_t with overflow detection ?
A sometimes useful fact, if you know that overflow behaves as addition
mod 2^N (where N is the size in bits), is that a+b overflows if and
only if a+b < a (for positive a and b). So you can do the addition
and check for overflow by comparing the result to either of the
operands. For unsigned integer types in C, overflow must behave this
way. For signed types, it is still true for most implementations.
-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
.
- Follow-Ups:
- Re: Detecting overflows while computing off_t
- From: Ben Pfaff
- Re: Detecting overflows while computing off_t
- From: pete
- Re: Detecting overflows while computing off_t
- Prev by Date: Re: The lack of a boolean data type in C
- Next by Date: Re: The lack of a boolean data type in C
- Previous by thread: Re: Detecting overflows while computing off_t
- Next by thread: Re: Detecting overflows while computing off_t
- Index(es):
Relevant Pages
|
|