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: dewar@merv.cs.nyu.edu (Robert Dewar) Subject: Re: Java vs Ada 95 (Was Re: Once again, Ada absent from DoD SBIR solicitation) Date: 1996/10/15 Message-ID: #1/1 X-Deja-AN: 189673681 references: <325D7F9B.2A8B@gte.net> organization: New York University newsgroups: comp.lang.ada Date: 1996-10-15T00:00:00+00:00 List-Id: Robert Duff said "How about portability of arithmetic? In Java, int is always exactly 32 bits 2's complement. In Ada, Integer is whatever the machine supports. And if I say "type T is range 1..100;" I might get 32-bit arithmetic, or I might get 8-bit arithmetic, or who-knows-what. In Java, 64-bit integers are supported, and no more. In Ada, 64-bit integers are supported by GNAT, but not by other compilers. A compiler could support more, or less, according to its whim. Is "type T is range 1..10**10;" legal? It is on *some* Ada compilers, but not others. On the other hand, at least Ada notifies you of overflows -- in Java, it just silently gets the wrong answer. (This is the C and C++ culture -- Java inherits much more than just syntax from that culture.)" That seems a bit confused. You get portable arithmetic in Ada by specifying the range. That gives you completely portable arithmetic, certainly up to 32 bits in practice. If you say type T is range 1 .. 100, then it does not matter if you get 8 bit or 32 bit arithmetic if you avoid overflowing this range. As you note, in Java overflows are ignor3ed in any case. So to get EXACTLY the equivalent of the Java int semantics, we do type int is range - 2 ** 31 .. + 2 ** 31 - 1; sure, a compiler can give you more than 32 bits, but providing you avoid overflow that is irrelevant, and if you have overflow, then Java arithemtic would also be undefined.