🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.ada
Article #969

(none)

#969
From: "Pat Rogers, High Tech Lab"
Date: Mon, 22 Sep 1986 16:36
88 lines
2666 bytes
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
Technical Details
Message-ID: <8609261055.AA13918@ucbvax.Berkeley.EDU>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!caip!nike!ucbcad!ucbvax!uhcl.CSNET!ROGERS

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!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: <8609261055.AA13918@ucbvax.Berkeley.EDU>
Date: Mon, 22-Sep-86 12:36:00 EDT
Article-I.D.: ucbvax.8609261055.AA13918
Posted: Mon Sep 22 12:36:00 1986
Date-Received: Fri, 26-Sep-86 20:58:19 EDT
Sender: daemon@ucbvax.BERKELEY.EDU
Organization: The ARPA Internet
Lines: 88