From: Craig Carey <research@ada95.ijs.com>
Subject: Re: have to use unrestricted access but just what about access
Date: Sat, 20 Jul 2002 04:59:40 GMT
Date: 2002-07-20T04:59:40+00:00 [thread overview]
Message-ID: <b1qhjus95qr6f5ila0qg1mddechrblii6m@4ax.com> (raw)
In-Reply-To: 5ee5b646.0206210345.2d58d8e0@posting.google.com
On 21 Jun 2002 04:45:08 -0700, dewar@gnat.com (Robert Dewar) wrote:
>Robert A Duff <bobduff@shell01.TheWorld.com> wrote in message news:<wccznxqni7o.fsf@shell01.TheWorld.com>...
>> "chris.danx" <spamoff.danx@ntlworld.com> writes:
>>
>> > How can the unrestricted_access attribute be replaced by just access in the
>> > following code?
>>
>> You should be using 'Unchecked_Access here, which is a standard feature
>> of Ada (albeit unsafe).
>>
>> 'Unrestricted_Access is a feature of GNAT, and is not necessary in your
>> example.
>>
>> - Bob
>
>Bob look again!
>
>One of the nasty restrictions in Ada 95 is that you cannot make parameters
>aliased. This means that they can never be used in access attributes. This
>is indeed one use of unrestricted access that is useful and legitimate, though
>of course passing such an access value out assumes call by reference, and you
>have to be sure that you can gaurantee call by reference.
Isn't having a parameter mode by "by-reference" about the same as having
it aliased. A type can be made to be by-reference using "pragma Voltile".
(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:
-----------------------------------------------------------
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)
next prev parent reply other threads:[~2002-07-20 4:59 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 [this message]
2002-07-20 17:47 ` Robert A Duff
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