comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: have to use unrestricted access but just what about access
Date: Sat, 20 Jul 2002 17:47:07 GMT
Date: 2002-07-20T17:47:07+00:00	[thread overview]
Message-ID: <wcc65zapa04.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: b1qhjus95qr6f5ila0qg1mddechrblii6m@4ax.com

Craig Carey <research@ada95.ijs.com> writes:

> Isn't having a parameter mode by "by-reference" about the same as having
> it aliased.

No.  If you look up the definition of "aliased", I don't think you'll
find any mention of "by reference".

If a parameter is aliased, then it had better be passed by reference.
But that's a rule for the language designer to obey, not the programmer.
For example, in Ada tagged parameters are aliased, and they are passed
by reference.

But the other way around is not true: passing a parameter by reference
does not imply that it's aliased.

>... A type can be made to be by-reference using "pragma Voltile".

But you wouldn't want to do that, because it might damage efficiency.

To make a type be by-reference, make it a limited record.
If it's scalar, wrap it inside a limited record.

To make a parameter aliased, make it's type tagged.
(Yuck; I don't like that rule.)

> (That statement can be put inside of the record that points into itself,
> and affect the record type and the type that is a pointer to that
>  record).
> 
> AARM 6.2 "Formal Parameter Modes", 10.e says:
>      C.6, ``Shared Variable Control'' says that a composite type with an
>      atomic or volatile subcomponent is a by-reference type, among other
>      things.
> 
> AARM & RM C.6 Shared Variable Control, 18 says:
>      If a type is atomic or volatile and it is not a by-copy type, then
>      the type is defined to be a by-reference type. If any subcomponent
>      of a type is atomic or volatile, then the type is defined to be a
>      by-reference type.
> 
> If a field were made Volatile then the whole record ought be
>  passed by reference, i.e. be aliased, according to AARM's C.6.
> 
> Here is some code that compiles on ObjectAda and GNAT:

In the code below, Dot_Window is tagged, and therefore is a pass-by-ref
type.  No need for the Volatile business (unless you wanted volatile for
other reasons).

I'm not sure why you put Volatile on Watcher_Access, but in any case, it
is a by-copy type (even with the Volatile).  Note the "and it is not a
by-copy type" wording in C.6.

> -----------------------------------------------------------
> package Ptr_Into_Rec is
> 
>    type Main_Window_Type is tagged limited null record;
> 
>    type Coordinator is null record;
>    type Watcher_Access is access all Coordinator;
>    type Ensure_By_Reference is private;
> 
>    pragma Volatile (Coordinator);
>    pragma Volatile (Watcher_Access);
> 
>    type Dot_Window is new Main_Window_Type
>       with record
>          Key_Coordinator : aliased Coordinator;
>          Watcher         : Watcher_Access;
>          Dont_Use        : Ensure_By_Reference;
>       end record;
> 
>    procedure Update (X : in out Dot_Window);
> 
> private
>    type Ensure_By_Reference is mod 2;
>    pragma Volatile (Ensure_By_Reference);
>    pragma Volatile (Dot_Window);
> end Ptr_Into_Rec;
> 
> 
> package body Ptr_Into_Rec is
> 
>    procedure Update (X : in out Dot_Window) is
>    begin
>       X.Watcher := X.Key_Coordinator'Unchecked_Access;
>    end Update;
> 
> end Ptr_Into_Rec;
> 
> -----------------------------------------------------------
> 
> My experimental StriUnli strings package (a replacement for Unbounded
>  Strings that allows pointer swapping) uses a record that points back
>  into itself. StriUnli:
>  http://www.ijs.co.nz/code/ada95_strings_http_hdrs.zip
> 
> 
> It doesn't seem to be unsafe.
> 
> 
> Craig Carey,
> 
>  http://www.ijs.co.nz/ada_95 (some Ada 95 mailing lists)



  reply	other threads:[~2002-07-20 17:47 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-19 23:32 have to use unrestricted access but just what about access chris.danx
2002-06-20  8:41 ` chris.danx
2002-06-20 12:10 ` SteveD
2002-06-20 14:22 ` Robert A Duff
2002-06-21 11:45   ` Robert Dewar
2002-06-22  0:49     ` Robert A Duff
2002-06-22  1:05       ` Ted Dennison
2002-06-22 12:09         ` Robert Dewar
2002-07-20  4:59     ` Craig Carey
2002-07-20 17:47       ` Robert A Duff [this message]
2002-07-21  8:45         ` Craig Carey
2002-06-20 16:05 ` Robert Dewar
2002-06-20 17:11   ` chris.danx
replies disabled

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