comp.lang.ada
 help / color / mirror / Atom feed
From: progers@acm.org
Subject: Re: Type conversion between access types (was: Free'ing extended types)
Date: 1996/05/23
Date: 1996-05-23T00:00:00+00:00	[thread overview]
Message-ID: <4o22no$9ej@uuneo.neosoft.com> (raw)
In-Reply-To: Drv666.92J@world.std.com


In <Drv666.92J@world.std.com>, bobduff@world.std.com (Robert A Duff) writes:
>In article <leschkes.832803959@ferret>,
>Scott Leschke <leschkes@ferret.cig.mot.com> wrote:
>>So what about 'all' causes the conversion to be allowed?  I looked at
>>section 4.6 of the LRM but got a tad confused?
>
>If you write "all", then it's called a "general access type".  4.6(13)
>allows conversion from an access type (general or pool-specific) to a
>general access type.  4.6(21) says that if the target type doesn't fall
>into one the cases allowed previously, then you can only convert within
>the same tree of derived types.  (I suspect that derived access types
>are unusual, so that would probably not apply.)

Derived access type conversion is unusual, at least in my experience,
but it sure is handy when you need it (in this case to prevent infinite
recursion on "="):

package Dynamic_Strings is 

  type Text is limited private;
 
  function "="( Left, Right : Text ) return Boolean;

  ...

private

  type Internal is access String;

  type Text is new Internal;

end Dynamic_Strings;



package body Dynamic_Strings is


  function "="( Left, Right : Text ) return Boolean is
  begin
    if ( Internal(Left) = null ) and ( Internal(Right) = null ) then
      return True;
    elsif ( Internal(Left) = null ) xor ( Internal(Right) = null ) then
      return False; -- since one points to an object & the other to nada
    else -- both refer to objects...
      return ( Left.all = Right.all );
    end if;
  end "=";

  ...

end Dynamic_Strings;




pat
---------------
Patrick Rogers
progers@acm.org





  reply	other threads:[~1996-05-23  0:00 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-04-28  0:00 Free'ing extended types Jonas Nygren
1996-04-28  0:00 ` Robert Dewar
1996-04-29  0:00   ` Laurent Guerby
1996-04-29  0:00     ` Robert A Duff
1996-04-29  0:00       ` Robert Dewar
1996-04-29  0:00   ` Jonas Nygren
1996-04-29  0:00     ` Robert A Duff
1996-04-29  0:00       ` Jonas Nygren
1996-04-29  0:00       ` Robert Dewar
1996-04-29  0:00         ` Robert A Duff
1996-05-20  0:00       ` Type conversion between access types (was: Free'ing extended types) Scott Leschke
1996-05-21  0:00         ` Robert A Duff
1996-05-22  0:00           ` Scott Leschke
1996-05-23  0:00             ` Robert A Duff
1996-05-23  0:00               ` progers [this message]
1996-05-24  0:00               ` Scott Leschke
1996-05-24  0:00                 ` Robert A Duff
1996-05-21  0:00         ` Dale Stanbrough
1996-05-21  0:00           ` Robert A Duff
1996-04-29  0:00   ` Free'ing extended types Laurent Guerby
1996-04-29  0:00     ` Robert A Duff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox