comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@world.std.com>
Subject: Re: "out" or "access"
Date: 1998/10/22
Date: 1998-10-22T00:00:00+00:00	[thread overview]
Message-ID: <wccr9w1bfav.fsf@world.std.com> (raw)
In-Reply-To: 70kvnv$gvo$1@supernews.com

"Pat Rogers" <progers@NOclasswideSPAM.com> writes:

> A bit too strong there, IMHO.  Access parameters are a very handy
> alternative when you want to derive from a type that has primitive
> subprograms with a formal parameter of a named access type.  Why?
> Because access parameters are not named access types, so the
> derivation provides primitives with the desired signatures.  For
> example:
> 
>   type T1 is tagged ...
> 
>   type T1_Pointer is access T1;
> 
>   procedure Foo( This : in T1;   That : in T1_Pointer );

But in *most* cases, "That" should be either "in out T1" or "in out
T1'Class".  You only need it to be a pointer in certain special cases
(eg you want Foo to save the pointer into some global data structure).
I agree that if you need a pointer, "access T1" is often what you want.

I agree with the other posters, who said to use "out" or "in out"
usually, and only use "access" if there's some particular reason for it.

I must admit, thought that it's annoying that T2_Pointer is not
implicitly convertible to T1_Pointer.  That conversion is perfectly safe
(whereas the other direction involves a run-time check, and should be
explicit).

> Then, in a derivation:
> 
>   type T2 is new T1 with ...
> 
> This gives us:
> 
> 
>   procedure Foo( This : in T2;  That : in T1_Pointer );
> 
> Note that the type of the formal 'That' is still T1_Pointer,
> probably not what we wanted.
> 
> On the other hand, had we defined things as:
> 
>   type T1 is tagged ...
> 
>   -- don't need this now...  type T1_Pointer is access T1;
> 
>   procedure Foo( This : in T1;   That : access T1 );
> 
> The derivation would provide
> 
>   procedure Foo( This : in T2;   That : access T2 );
> 
> which is probably the desired result in this case.

- Bob
-- 
Change robert to bob to get my real email address.  Sorry.




      parent reply	other threads:[~1998-10-22  0:00 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-10-21  0:00 "out" or "access" =:-) Vincent
1998-10-21  0:00 ` dennison
1998-10-21  0:00 ` Tucker Taft
1998-10-22  0:00   ` Pascal Obry
1998-10-29  0:00     ` Robert A Duff
1998-10-29  0:00       ` Matthew Heaney
1998-10-29  0:00         ` Robert A Duff
1998-10-30  0:00           ` dennison
1998-10-30  0:00             ` Matthew Heaney
1998-10-30  0:00               ` Robert A Duff
1998-10-31  0:00                 ` Matthew Heaney
1998-11-01  0:00                   ` Robert A Duff
1998-11-01  0:00                     ` Matthew Heaney
1998-11-01  0:00                       ` Robert A Duff
1998-11-02  0:00                         ` Matthew Heaney
1998-11-03  0:00                           ` Simon Wright
1998-11-16  0:00                             ` Matthew Heaney
1998-10-31  0:00                 ` dewar
1998-10-31  0:00                   ` Matthew Heaney
1998-10-21  0:00 ` Jeff Carter
1998-10-21  0:00   ` Pat Rogers
1998-10-21  0:00     ` Martin C. Carlisle
1998-10-22  0:00       ` Pat Rogers
1998-10-22  0:00     ` Robert A Duff [this message]
replies disabled

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