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,3ccb707f4c91a5f2 X-Google-Attributes: gid103376,public From: bobduff@world.std.com (Robert A Duff) Subject: Re: Portability of Arithmetic (was: Java vs Ada 95) Date: 1996/10/17 Message-ID: #1/1 X-Deja-AN: 190069450 references: <325D7F9B.2A8B@gte.net> <1996Oct15.174526.1@eisner> organization: The World Public Access UNIX, Brookline, MA newsgroups: comp.lang.ada Date: 1996-10-17T00:00:00+00:00 List-Id: In article , Robert Dewar wrote: >I am not sure I understand Bob's statement here. The above code is certainly >not valid Java code, so what does it mean to say that the above code works >in Java. To write it in Java, you would use type 'int' or type 'char' or whatever, and it would be portable. I admit it's not an exact comparison, since Java doesn't have subranges (an important disadvantage of Java, IMHO). I also admit that the lack of overflow checking in Java weakens my point. >... If you mean it is possible to write this in a manner that works >in Java, then the same statement can be made in Ada: > > type BT is range 1 .. 200; > subtype T is BT range 1 .. 100; > X : T := ...; > Y : T := ...; > Average : T := (X + Y)/2; > >works fine. You can write invalid Ada code for anything, but doing so >does not prove anything! True, but it's easy to do it wrong, and have it work just fine, and then find that it doesn't work when you port the code. Do all Ada programmers understand that the above has to be written as you show above? I suspect not. But I suspect all Java programmers understand what the range of int is, and when arithmetic is supposed to work. What about the following? type T is range 1..100; X: T := 100; Y: T := 1; Z: T := 100; ... Z := Z + X - Y; This will work fine in every Ada compiler that now exists or that ever will exist. But it's not guaranteed to work by the RM. So, as a style rule, should I declare a base subtype that goes up to 101 for the above? I'm not sure. Of course, Java will run horribly slowly on a machine with 36-bit words. Ada was defined when such machines were more common. - Bob