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: 103376,fee8802cc3d8334d X-Google-Attributes: gid103376,public X-Google-Thread: 10a146,fee8802cc3d8334d X-Google-Attributes: gid10a146,public From: mgk25@cl.cam.ac.uk (Markus Kuhn) Subject: Re: Ada and Java. different behaviour. casting long to int problem. Date: 1999/06/17 Message-ID: <7kb9ep$hej$1@pegasus.csx.cam.ac.uk>#1/1 X-Deja-AN: 490733656 References: <7jt2c0$vrb@drn.newsguy.com> <7jv4bh$11rg@drn.newsguy.com> <7jvcqv$od9$1@nnrp1.deja.com> <7jvj7r$1nj8@drn.newsguy.com> Organization: U of Cambridge Computer Lab, UK Newsgroups: comp.lang.ada,comp.lang.java.programmer Date: 1999-06-17T00:00:00+00:00 List-Id: Mark Hood writes: |> > In Java, nothing happens, and life goes on and the final number is wrong, |> > but no one really knows it is wrong, or may be someone will notice it is |> > wrong. |> |> I think the point is that the result of an overflow isn't necessarily the |> wrong number. |> |> For example, one could be working with data that needs to be expressed in |> some signed 16-bit quantized space, and wish to encode consecutive elements |> in that space as deltas from previous values in a streamed fashion. In that |> case the overflow semantics are essential, since otherwise it wouldn't be |> possible to express the delta between -30000 and +30000 in 16 bits. |> |> The example isn't contrived; it's common in compression algorithms. My |> impression is that Ada is oriented toward numerical applications, and so the |> overflow checks are probably appropriate. It would certainly be |> inconvenient for many Java applications if the defined behavior of signed |> 2's complement integers were thwarted. Just for the record: Ada95 does have so-called "modular integer types" such as Unsigned_8, Unsigned_64, etc. These do overflow without raising any exception, for exactly the applications that you mentioned, just like the corresponding unsigned int types in C. If X is a modular type, then you always get X'Last + 1 = 0 in Ada95. (X'Last is just the Ada notation for the highest possible value that variable X can possibly have, e.g. 255 for X : Unsigned_8). Modular integer types were one of the many important improvements that were made to Ada in the 1995 complete revision of the language, and they are invaluable for high-performance coding of many signal processing algorithms. Your impression that Ada is "oriented toward numerical applications" is not true any more for the modern Ada95 language that the GNAT compiler implements. Ada95 is in my experience at least as well suited for high-performance bit fiddling in data compression, data encryption, and signal processing algorithms as C is. But in addition to C, you get the safety and comfort features of Java as well. For me, Ada95 combines the best of both the C and the Java world: High performance, low-level access as well as type safety, and comfort. It is amazing how underhyped this equally young language is compared to Java in the trade press. But then, who asks the trade press ... Markus -- Markus G. Kuhn, Computer Laboratory, University of Cambridge, UK Email: mkuhn at acm.org, WWW: