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: "Robert I. Eachus" Subject: Re: Ada and Java. different behaviour. casting long to int problem. Date: 1999/06/17 Message-ID: <37694942.2C87628A@mitre.org>#1/1 X-Deja-AN: 490775199 Content-Transfer-Encoding: 7bit References: <7jt2c0$vrb@drn.newsguy.com> <7k57vb$1ipf@drn.newsguy.com> <3766650F.705125B7@pwfl.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: The MITRE Corporation Mime-Version: 1.0 Newsgroups: comp.lang.ada,comp.lang.java.programmer Date: 1999-06-17T00:00:00+00:00 List-Id: Marin David Condic wrote: > If one wants wraparound semantics, then > perhaps there should be a special type to support that behavior - a la > modular types in Ada. (Although these don't contain negative numbers and > that may be a requirement.) In some cases, saturation semantics are a > good thing, but again, this is not the "normal" understanding of > arithmetic and therefore should be supported by a special type. Interesting question, but far from this topic... If you want a type with negative numbers that wraps around in Ada, how do you do it? Pragma Suppress is the easiest solution, but it is not guarenteed to work portably, or even to work at all. You can derive a type from a modular type and override the comparison operators, etc. This is probably the best route. The cleanest way from a users point of view is probably to derive from Integer and override the arithmetic operations. This does have the problem with reemergence of the predefined operators (see RM 12.5(8)) in a generic when one of these types is passed as a generic formal integer type rather than a generic formal derived type. However, I think that this is probably the right behavior--let the author of the generic worry about overflow inside the generic. If you want to use the redefined operators, you can always pass them as genric formal subprograms. To bring this discussion back on topic, probably the best solution for compilers that want to interface cleanly with Java, is to provide an Interfaces.Java package, with an explicitly non-standard integer type that can be converted to and from an Ada integer type. -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...