Re: detecting two's complement arithmetics
From: Mycroft Holmes (m.holmes_at_nospam.it)
Date: 11/03/04
- Next message: Hans De Smaele: "Re: debugging"
- Previous message: Oleg Starodumov: "Re: Viewing STL container content in VC watch windows?"
- In reply to: Bo Persson: "Re: detecting two's complement arithmetics"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 3 Nov 2004 09:27:31 +0100
>
> But overflow is not allowed!
>
> "If during the evaluation of an expression, the result is not
> mathematically defined or not in the range of representable values for
> its type, the behavior is undefined, unless such an expression is a
> constant expression (5.19), in which case the program is ill-formed."
> (Chapter 5, paragraph 5)
>
> In other words, if it overflows during runtime, you cannot trust the
> result (or anything else). If it overflows at compile time, it is not a
> valid C++ program!
>
unsigned integers must use modular arithmetics, so they cannot overflow, the
simply restart from 0.
so if int_t were unsigned, it would be ok.
if int_t is signed and the machine uses two's complement, ~0 is -1, and
there's no overflow.
otherwise (I understand from your words) the compiler is required to give an
error, isn't it?
If that's true, my test is satisfactory.
-- The set of solutions is never empty. Two solutions together form a new problem. -- Mycroft Holmes
- Next message: Hans De Smaele: "Re: debugging"
- Previous message: Oleg Starodumov: "Re: Viewing STL container content in VC watch windows?"
- In reply to: Bo Persson: "Re: detecting two's complement arithmetics"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|