From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 28 Jun 93 23:37:20 GMT From: dst17!mab@ford-wdl1.arpa (Mark A Biggar) Subject: Re: Ada Operators in 9x Message-ID: <1993Jun28.233720.14990@wdl.loral.com> List-Id: In article <1993Jun28.203652.5542@relay.nswc.navy.mil> bwallet@apssgi.nswc.navy .mil (Brad Wallet) writes: >an interesting little problem operators gave me lately: >package MY_INTEGER is > subtype INTEGER_16 is private; --# Defines a sixteen bit integer. > function "+" > (LEFT : in INTEGER_16; --* Left operand of the addition. > RIGHT : in INTEGER_16) --* Right operand of the addition. > return INTEGER_16; --/ This function returns the sum of two sixteen bit integers. >private > type INTEGER_16 is INTEGER range -32_767..32_767; > for INTEGER_16'size use 16; >end MY_INTEGER; >package body MY_INTEGER is > function "+" > (LEFT : in INTEGER_16; > RIGHT : in INTEGER_16) > return INTEGER_16 is > begin > return (LEFT + RIGHT); -- (1) > end "+"; >end MY_INTEGER; This recurses until you run out of stack memory. By the overloading rules, the only matching operation for "+" at (1) is the "+" you are currently defining (which must be available because there is no other way to get recursion when you really DO want it.) In order to get what you really wanted you need to say: return (INTEGER_16(INTEGER(LEFT)+INTEGER(RIGHT)); or something similar. Now the overloading rules make the "+" for INTEGER the only usable version of "+". Note the the conversion back to INTEGER_16 will raise CONSTRAINT_ERROR on overflow, which is probably what you want anyway. -- Mark Biggar mab@wdl.loral.com