RE: Euphoria versus Java

new topic     » goto parent     » topic index » view thread      » older message » newer message

Pete:
I didn't know that C checked for integer overflow in some way. Rather, I
thought that it didn't check it at all, for performance reasons.
Testing this hypothesis, I programmed a simple loop in C. When an integer
would exceed the maximum corresponding integer size (say 32767), it simply
(this time actually "simply") reverts to a perfectly fixed value, that is,
the maximum negative number (assuming you were adding 1 to it), and not to
an indeterminate or rubbish value. This means it doesn't disturb what the
hardware does.
I made the same test in Java, with identical results. Moreover, a loop using
pre-defined variables (int, short, long, etc.), not objects, in Java under
Micro$oft Visual J++ 6.0 takes *less* time, believe it or not, than the same
one under Visual C++. This suggests Java performs at least fewer or the same
tests than C++, or maybe it has better optimizations. Strangely enough, the
timings were the same, no matter the resulting executable was .class or
.exe. I have no explanation for this.
Regards.
PS: Do you know if you can do in Java the same that you do in C#, as you
explained?
----- Original Message -----
From: Pete Lomax <petelomax at blueyonder.co.uk>
To: EUforum <EUforum at topica.com>
Sent: Monday, April 07, 2003 3:31 AM
Subject: Re: Euphoria versus Java



On Sun, 6 Apr 2003 15:32:06 -0300, rforno at tutopia.com wrote:

>I'm using a bit of Java now, and I noticed the following: while Java
>routinely performs a subscript checking (unlike C/C++), it does not verify
>if byte, short, integer or long variables overflow. So, if you have:
>byte x = 127;
>x = x + 1;
>you end up with x = -128 instead of getting an overflow error.
>Please correct me if there is a way of checking for this kind of error
>(someone in the list may know more Java than I do ;)).

Java uses the ansi standard C overflow checking model. Basically, when
overflow occurs, some useless rubbish is stored in the result field...
and then program execution continues at the next statement blink

In C# instead of z=x+y you can just simply(!!) write:

try {
        z = checked(x + y);
}
catch (System.OverflowException e) {
        System.Console.WriteLine(e.ToString());
}

==^^===============================================================
This email was sent to: rforno at tutopia.com


TOPICA - Start your own email discussion group. FREE!

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu