From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,50137bb64a119cfc X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-02-19 18:20:45 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: mheaney@on2.com (Matthew Heaney) Newsgroups: comp.lang.ada Subject: Re: "access constant" discriminant Date: 19 Feb 2003 18:20:45 -0800 Organization: http://groups.google.com/ Message-ID: <1ec946d1.0302191820.46fbbd03@posting.google.com> References: <_TO1a.14664$9y2.6601@nwrddc01.gnilink.net> <3CS1a.55972$2H6.1357@sccrnsc04> NNTP-Posting-Host: 66.162.65.162 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1045707645 8013 127.0.0.1 (20 Feb 2003 02:20:45 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 20 Feb 2003 02:20:45 GMT Xref: archiver1.google.com comp.lang.ada:34241 Date: 2003-02-20T02:20:45+00:00 List-Id: 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.