From: nabbasi@pacbell.net.NOSPAM
Subject: Re: Ada and Java. different behaviour. casting long to int problem.
Date: 1999/06/12
Date: 1999-06-12T00:00:00+00:00 [thread overview]
Message-ID: <7jt69l$143f@drn.newsguy.com> (raw)
In-Reply-To: 7jt2c0$vrb@drn.newsguy.com
In article <7jt2c0$vrb@drn.newsguy.com>, nabbasi@pacbell.net says...
>In the example, I cast a long integer literal, outside the range
>of an integer, into an integer variable. Java allows this,
>and produces the wrong result. Ada compiler detect this as an error
>at compile time, and it also detects the same thing at run-time.
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
actually that was an error of mine, it did not detect it at run-time,
only at compile time. see below
>------------------- ada example 2 -----------------------------
>
>with Ada.Text_Io; USE Ada.Text_Io;
>
>procedure Test_Cast is
> N : Long_Integer;
> M : Integer;
> package Long_Int_Io is new Ada.Text_Io.Integer_Io(Long_Integer);
>begin
> Long_Int_Io.Get(N);
> M := Integer (N);
>
> Put_Line ( "long n =" & Long_integer'Image(N)
> & "int m =" & Integer'Image(M) );
>end Test_Cast;
>
>$./test_cast <--- run
>3200000000
>
>raised ADA.IO_EXCEPTIONS.DATA_ERROR <-- exception raised
>-------------------------------------------------------------
This was an input error which I do not understand now why.
This is a modified Ada program, that shows Ada did not detect at
run-time the overflow (I think may be I am not using the correct
GNAT flag to enable run-time chekcing? I need to check more on this)
-------------------------------------
with Ada.Text_Io; USE Ada.Text_Io;
procedure Test_Cast is
N : Long_Integer;
M : Integer;
package Long_Int_Io is new Ada.Text_Io.Integer_Io(Long_Integer);
begin
N := 2000000000;
M := Integer (N);
M := M*2;
Put_Line ( "long n =" & Long_integer'Image(N)
& "int m =" & Integer'Image(M) );
end Test_Cast;
------------------------------------------
$./test_cast
long n = 2000000000int m =-294967296
^^^^^^^^^^^^^^
???
Nasser
next prev parent reply other threads:[~1999-06-12 0:00 UTC|newest]
Thread overview: 120+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-06-12 0:00 Ada and Java. different behaviour. casting long to int problem nabbasi
1999-06-12 0:00 ` nabbasi [this message]
1999-06-12 0:00 ` jerry
1999-06-12 0:00 ` Robert Dewar
1999-06-14 0:00 ` Marin David Condic
1999-06-12 0:00 ` Tucker Taft
1999-06-12 0:00 ` PPAATT
1999-06-12 0:00 ` Keith Thompson
1999-06-12 0:00 ` kirck
1999-06-13 0:00 ` Robert Dewar
1999-06-12 0:00 ` Fred
1999-06-14 0:00 ` Mark Hood
1999-06-15 0:00 ` mike
1999-06-15 0:00 ` Samuel Mize
1999-06-15 0:00 ` jerry
1999-06-16 0:00 ` Richard D Riehle
1999-06-16 0:00 ` jerry
1999-06-15 0:00 ` D'Arcy Smith
1999-06-16 0:00 ` George W. Bayles
1999-06-16 0:00 ` D'Arcy Smith
1999-06-17 0:00 ` Matthew Heaney
1999-06-17 0:00 ` Aidan Skinner
1999-06-15 0:00 ` Marin David Condic
1999-06-15 0:00 ` Mike Silva
1999-06-15 0:00 ` rich
1999-06-15 0:00 ` Marin David Condic
1999-06-15 0:00 ` D'Arcy Smith
1999-06-15 0:00 ` Keith Thompson
1999-06-16 0:00 ` bill
1999-06-16 0:00 ` George W. Bayles
1999-06-16 0:00 ` Fraser Wilson
1999-06-17 0:00 ` Chris Dollin
1999-06-17 0:00 ` Aidan Skinner
1999-06-17 0:00 ` David Botton
1999-06-18 0:00 ` Dale Stanbrough
1999-06-18 0:00 ` Matthew Heaney
1999-06-18 0:00 ` David Botton
1999-06-18 0:00 ` Pascal Obry
1999-07-20 0:00 ` Geoff Bull
1999-06-16 0:00 ` D'Arcy Smith
1999-06-16 0:00 ` George W. Bayles
1999-06-16 0:00 ` D'Arcy Smith
1999-06-16 0:00 ` Tucker Taft
1999-06-17 0:00 ` George W. Bayles
1999-06-17 0:00 ` Tucker Taft
1999-06-17 0:00 ` bob
1999-06-16 0:00 ` D'Arcy Smith
1999-06-17 0:00 ` Larry Kilgallen
1999-06-16 0:00 ` Marin David Condic
1999-06-16 0:00 ` Mike Silva
1999-06-16 0:00 ` D'Arcy Smith
1999-06-16 0:00 ` kirk
1999-06-16 0:00 ` D'Arcy Smith
1999-06-17 0:00 ` Markus Kuhn
1999-06-17 0:00 ` D'Arcy Smith
1999-06-17 0:00 ` john
1999-06-17 0:00 ` Ed Falis
1999-06-18 0:00 ` Aidan Skinner
1999-06-16 0:00 ` Hyman Rosen
1999-06-17 0:00 ` Markus Kuhn
1999-06-17 0:00 ` Jean-Pierre Rosen
1999-06-17 0:00 ` Marin David Condic
1999-06-17 0:00 ` Samuel Mize
1999-06-17 0:00 ` Marin David Condic
1999-06-22 0:00 ` Hyman Rosen
1999-06-22 0:00 ` Keith Thompson
1999-06-23 0:00 ` Marin David Condic
1999-06-24 0:00 ` Robert A Duff
1999-06-24 0:00 ` Marin David Condic
1999-06-23 0:00 ` Marin David Condic
1999-06-18 0:00 ` Aidan Skinner
1999-06-17 0:00 ` Robert I. Eachus
1999-06-17 0:00 ` Hyman Rosen
1999-06-17 0:00 ` Marin David Condic
1999-06-17 0:00 ` bob
1999-06-18 0:00 ` Hyman Rosen
1999-06-18 0:00 ` mike
1999-06-18 0:00 ` Hyman Rosen
1999-06-19 0:00 ` Dale Stanbrough
1999-06-21 0:00 ` Marin David Condic
1999-06-19 0:00 ` Samuel Mize
1999-06-21 0:00 ` Marin David Condic
1999-06-21 0:00 ` Mike Silva
1999-06-20 0:00 ` Sera Hirasuna
1999-06-19 0:00 ` Kio
1999-06-20 0:00 ` Vladimir Olensky
1999-06-21 0:00 ` Samuel T. Harris
1999-06-22 0:00 ` Robert I. Eachus
1999-06-23 0:00 ` Aidan Skinner
1999-06-23 0:00 ` Richard D Riehle
1999-06-22 0:00 ` Richard D Riehle
1999-06-21 0:00 ` Hyman Rosen
1999-06-17 0:00 ` Jean-Pierre Rosen
1999-06-22 0:00 ` Robert Dewar
1999-06-23 0:00 ` Marin David Condic
1999-06-23 0:00 ` Vladimir Olensky
1999-06-23 0:00 ` Roedy Green
1999-06-23 0:00 ` Marin David Condic
1999-06-23 0:00 ` Keith Thompson
1999-06-24 0:00 ` Marin David Condic
1999-06-24 0:00 ` Mike Silva
1999-06-23 0:00 ` Marin David Condic
1999-06-15 0:00 ` tmoran
1999-06-15 0:00 ` David Botton
1999-06-16 0:00 ` Richard D Riehle
1999-06-16 0:00 ` Samuel Mize
1999-06-15 0:00 ` Samuel Mize
1999-06-16 0:00 ` Mark Hood
1999-06-17 0:00 ` Jean-Pierre Rosen
1999-06-17 0:00 ` Robert I. Eachus
1999-06-17 0:00 ` Marin David Condic
1999-06-17 0:00 ` Markus Kuhn
1999-06-17 0:00 ` David Botton
1999-06-13 0:00 ` Robert Dewar
1999-06-14 0:00 ` tmoran
1999-06-30 0:00 ` John Merryweather Cooper
1999-07-01 0:00 ` Chad R. Meiners
1999-07-02 0:00 ` Robert Dewar
1999-07-02 0:00 ` John Merryweather Cooper
1999-07-03 0:00 ` Robert Dewar
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox