This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Constant fold -A - B as -B - A (take 2)

On 07-Feb-2003, Richard Kenner <> wrote:
> There is *no* language, as far as I know, for which MAX_INT + 1 is defined,
> let alone equal to MIN_INT.

What about Java, C#, and Visual Basic?

In Java, integers have finite precision with two's complement-style ranges
(i.e. MIN_INT = -MAX_INT - 1), and integer overflow always wraps.
So yes, MAX_INT + 1 is defined to be equal to MIN_INT (presuming
appropriate definitions of MAX_INT and MIN_INT, of course).
[JLS 4.2.2 says "the operation is carried out using 32-bit precision" and
"The built-in integer operators do not indicate overflow or underflow in
any way.".]

In C#, there are "checked" contexts and "unchecked" contexts;
in the former, integer overflow always raises an exception,
but in the latter, integer overflow always wraps, just like in Java.

For VB, it's the same as for C#.

Fergus Henderson <>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <>  |     -- the last words of T. S. Garp.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]