1. Euphoria versus Java

Rob:
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 ;)).
I think this is another point in favor of Euphoria that can be stressed.
Regards.

new topic     » topic index » view message » categorize

2. 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 =3D 127;
>x =3D x + 1;
>you end up with x =3D -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=3Dx+y you can just simply(!!) write:

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

new topic     » goto parent     » topic index » view message » categorize

3. Re: Euphoria versus Java

On Tue, 8 Apr 2003 00:03:06 -0300, rforno at tutopia.com wrote:

>
>Pete:
>I didn't know that C checked for integer overflow in some way.
LOL. I was being sarcastic, it handles overflow by ignoring it.
<snip>
> 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.
Predictable, yes, but useful, no (or only very rarely). Anything not
useful (as in 136+121=3D1) I class as rubbish.
>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.
I don't know enough to speak authoritatively on the relative merits of
java bytecode vs x86 machine code but I would guess that the java
runtime can optimise an increment-by-one opcode for certain cases
whereas C++ is probably just outputting a standard x86 machine code
block suitable for all cases.
> Strangely enough, the
>timings were the same, no matter the resulting executable was .class or
>.exe. I have no explanation for this.
Either the .exe works like Eu bound programs, whereby internally its
not any different, just has a copy of the interpreter bundled with it,
or the JIT compiler is at play.

>PS: Do you know if you can do in Java the same that you do in C#, as you
>explained?
No I don't think you can. I can't find any information on which
languages allow overflow checking. Python, C#, Euphoria are the only
ones as far as I know.

Pete

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu