From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10a146,fee8802cc3d8334d X-Google-Attributes: gid10a146,public X-Google-Thread: 103376,fee8802cc3d8334d X-Google-Attributes: gid103376,public From: stt@houdini.camb.inmet.com (Tucker Taft) Subject: Re: Ada and Java. different behaviour. casting long to int problem. Date: 1999/06/12 Message-ID: #1/1 X-Deja-AN: 488834683 Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.burl.averstar.com References: <7jt2c0$vrb@drn.newsguy.com> Organization: Intermetrics, Inc. Followup-To: comp.lang.ada,comp.lang.java.programmer Newsgroups: comp.lang.ada,comp.lang.java.programmer Date: 1999-06-12T00:00:00+00:00 List-Id: nabbasi@pacbell.net wrote: : This below shows that Ada detected at compile time a basic problem : that the Java compiler missed. (this might be specific problem : with the Java compiler I am using), it also could be a : mis-understanding on my part of the Java semantics when it : comes to this, but the bottom line is that Java produced, : what for me, can only be a wrong result. Integer conversion (casting) in Java is truncating. Integer conversion in Ada is value-preserving, with a run-time check on overflow (note that GNAT in some configurations suppresses overflow checks by default, which is naughty in some people's view ;-). To get truncation in Ada, you need to use an explicit "mod"/"rem" or Unchecked_Conversion. Java is largely following C/C++ semantics in this area, FWIW, though C/C++ provide *implicit* truncating conversions, whereas truncating conversions in Java must be explicit casts. : ... : Nasser -- -Tucker Taft stt@averstar.com http://www.averstar.com/~stt/ Technical Director, Distributed IT Solutions (www.averstar.com/tools) AverStar (formerly Intermetrics, Inc.) Burlington, MA USA