comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@on2.com (Matthew Heaney)
Subject: Re: "access constant" discriminant
Date: 19 Feb 2003 18:20:45 -0800
Date: 2003-02-20T02:20:45+00:00	[thread overview]
Message-ID: <1ec946d1.0302191820.46fbbd03@posting.google.com> (raw)
In-Reply-To: 3CS1a.55972$2H6.1357@sccrnsc04

tmoran@acm.org wrote in message news:<3CS1a.55972$2H6.1357@sccrnsc04>...
> >What is it that you want to do?
>    In the case at hand, I'm using the idiom of a limited controlled type
> whose initialization/finalization grabs/releases a resource lock, and the
> access discriminant tells which resource.
>   type Lock_Type(Resource : access Resource_Type) is new
>   Ada.Finalization.Limited_Controlled with ...
> and later
>   Locker : Lock_Type(Resource'unchecked_access);
>   ...
> But this won't work when Resource is an "in" parameter, eg a function
> parameter.  I suppose Ada is telling me that grabbing a lock is
> effectively modifying the resource, and thus something that shouldn't be
> done when the resource is an "in" parameter, but the question remains, why
> can't one say
>   type Lock_Type(Resource : access constant Resource_Type) ...
> Did the designers foresee and forestall my use with a function?

If your resource is limited, then use the Rosen Trick, and add a
handle to the type's representation:

procedure Op (Resource : in Resource_Type) is

  Lock : Lock_Type (Resource.Handle.Resource);
begin

where Handle is 

type Handle_Type (Resource : access Resource_Type) is
   limited null record;

type Resource_Type is
   limited record 
      Handle : Handle_Type (Resource_Type'Access);
      ...
   end record;

If your resource type isn't limited, then you can safely use
Address_To_Access_Conversions the type is pass-by-reference.



  parent reply	other threads:[~2003-02-20  2:20 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-10  8:26 "access constant" discriminant tmoran
2003-02-10 14:43 ` Frank J. Lhota
2003-02-10 18:57   ` tmoran
2003-02-15 19:17     ` Richard Riehle
2003-02-15 19:59       ` Larry Kilgallen
2003-02-15 23:53         ` Richard Riehle
2003-02-16  1:50           ` Eric G. Miller
2003-02-20  2:23         ` Matthew Heaney
2003-02-20 17:34         ` Stephen Leake
2003-02-21  0:42           ` Matthew Heaney
2003-02-21 10:41             ` Lutz Donnerhacke
2003-02-21 20:21               ` Randy Brukardt
2003-02-23 12:22                 ` Simon Wright
2003-02-24  7:06                 ` Dale Stanbrough
2003-02-24 18:58                 ` Matthew Heaney
2003-02-24 21:05                   ` Randy Brukardt
2003-02-25 14:15                     ` Frank J. Lhota
2003-02-26  1:05                       ` Randy Brukardt
2003-02-24 16:03               ` Matthew Heaney
2003-02-21 15:03             ` Hyman Rosen
2003-02-21 20:09               ` Randy Brukardt
2003-02-21 21:33               ` Matthew Heaney
2003-02-21 20:07             ` Randy Brukardt
2003-02-24 19:11               ` Matthew Heaney
2003-02-24 21:17                 ` Randy Brukardt
2003-02-25 17:49                   ` Richard Riehle
2003-02-20  2:23       ` Matthew Heaney
2003-02-20  2:20     ` Matthew Heaney [this message]
2003-02-10 19:26 ` Robert A Duff
2003-02-10 22:27 ` Rod Chapman
2003-02-11  2:00   ` Jeffrey Carter
2003-02-20  2:28   ` Matthew Heaney
2003-02-20  9:45     ` Lutz Donnerhacke
2003-02-20  2:17 ` Matthew Heaney
replies disabled

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