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=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!caip!nike!ucbcad!ucbvax!uhcl.CSNET!ROGERS From: ROGERS@uhcl.CSNET ("Pat Rogers, High Tech Lab") Newsgroups: net.lang.ada Subject: (none) Message-ID: <8609240624.AA15139@ucbvax.Berkeley.EDU> Date: Mon, 22-Sep-86 12:36:00 EDT Article-I.D.: ucbvax.8609240624.AA15139 Posted: Mon Sep 22 12:36:00 1986 Date-Received: Wed, 24-Sep-86 05:25:52 EDT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The ARPA Internet List-Id: Dear Ada language-lawyers, Here's a question: Given the following, package P is type LP is limited private; function "="( Left, Right : LP ) return LP; private type LP is new Integer; end P; Within the body for P."+", care must be taken to avoid a recursive call to P."+", via the following conversion: package body P is function "="( Left, Right : LP ) return LP is begin return Integer(Left) = Integer(Right); end "="; end P; Otherwise it will recursively call itself since there is a visible operator "=" defined for two parameters of type LP, thus hiding the predefined operator (see RM 7.4.2/5, last sentence). So, well enough. Now the question: suppose that LP is actually an access type, rather than derived from Integer. So, package P is type LP is limited private; function "="( Left, Right : LP ) return Boolean; private type LP is access Integer; -- or access whatever end P; In the body, the above approach cannot be used, since there is no conversion or qualification type available. To wit, package body P is function "="( Left, Right : LP ) return Boolean is begin if Left = null then ... This is a recursive call to P."=" on my compiler (yes, validated). One could simply do the following (my current approach), begin return Left.all = Right.all; -- null pointer dereference possible exception when Constraint_Error => return False; end "="; However, in some situations it may be desirable to check for the null value rather than relying on Constraint_Error (which might be suppressed later by another programmer, etc... ). Maybe it is just correct in some particular application to have two objects of type LP be equal if they are both null. In those cases, what can be done ? Is the compiler correct ? I've not had time to check it on some others. Any suggestions will be appreciated. Thanks ! Pat Rogers High Tech Lab University of Houston at Clear Lake