Re: efficiency concern: when to really use unsigned ints and when not to
From: CBFalconer (cbfalconer_at_yahoo.com)
Date: 02/16/04
- Next message: CBFalconer: "Re: undefined behavior or not undefined behavior? That is the question"
- Previous message: P.J. Plauger: "Re: 'erf' function in C"
- In reply to: anony*mouse: "Re: efficiency concern: when to really use unsigned ints and when not to"
- Next in thread: Flash Gordon: "Re: efficiency concern: when to really use unsigned ints and when not to"
- Reply: Flash Gordon: "Re: efficiency concern: when to really use unsigned ints and when not to"
- Reply: Flash Gordon: "Re: efficiency concern: when to really use unsigned ints and when not to"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 16 Feb 2004 20:12:59 GMT
anony*mouse wrote:
>
... snip ...
>
> As an exercise consider the additional checks that need to be
> taken in the check() function below. How many would be removed
> by making a and b unsigned?
>
> int check(signed int a, signed int b)
> {
> /* a and b are considered untrusted numbers. */
>
if ((a < 0) || (b < 0)) return 0;
> if (a + b < 50)
> return 1;
> else
> return 0;
> }
The above suffices for any system which has integer overflow
detection. Now consider the ugly tests required if a and b are
unsigned, so that overflow of a + b cannot occur.
-- Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net) Available for consulting/temporary embedded and systems. <http://cbfalconer.home.att.net> USE worldnet address!
- Next message: CBFalconer: "Re: undefined behavior or not undefined behavior? That is the question"
- Previous message: P.J. Plauger: "Re: 'erf' function in C"
- In reply to: anony*mouse: "Re: efficiency concern: when to really use unsigned ints and when not to"
- Next in thread: Flash Gordon: "Re: efficiency concern: when to really use unsigned ints and when not to"
- Reply: Flash Gordon: "Re: efficiency concern: when to really use unsigned ints and when not to"
- Reply: Flash Gordon: "Re: efficiency concern: when to really use unsigned ints and when not to"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|