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,daf1e35a4e978e9d X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-07-19 21:59:56 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed-east.nntpserver.com!nntpserver.com!easynews!nntp2.aus1.giganews.com!nntp.giganews.com!nntp3.aus1.giganews.com!bin2.nnrp.aus1.giganews.com.POSTED!news.clear.net.nz From: Craig Carey Newsgroups: comp.lang.ada Subject: Re: have to use unrestricted access but just what about access Message-ID: References: <0x8Q8.6779$ZP1.1263481@news11-gui.server.ntli.net> <5ee5b646.0206210345.2d58d8e0@posting.google.com> X-Newsreader: Forte Agent 1.9/32.560 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Organization: Customer of Mercury Telecommunications Ltd Cache-Post-Path: drone3-svc-skyt.qsi.net.nz!unknown@tnt1-15.quicksilver.net.nz X-Cache: nntpcache 2.4.0b5 (see http://www.nntpcache.org/) X-Original-NNTP-Posting-Host: drone3-svc-skyt.qsi.net.nz X-Original-Trace: 20 Jul 2002 16:59:10 +1200, drone3-svc-skyt.qsi.net.nz NNTP-Posting-Date: Fri, 19 Jul 2002 23:59:40 CDT X-Trace: sv3-8zSq274kOhH71etBonK0gKL52rFryZI84Giofj4/e3H1/ddk/hwErZ8LCAYRBNb5a/ywxE4DNXZDsd+!dFhCYbaKKKe/bz7dm8BeBouIa3eScR7MNB67VDiRuGJYCcy8PKTPr0v7RnIpjgor6TONcOE+jV6T!oV+0SQ== X-Complaints-To: abuse@GigaNews.Com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-Info: Please be sure to forward a copy of ALL headers X-Abuse-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.1 Date: Sat, 20 Jul 2002 04:59:40 GMT Xref: archiver1.google.com comp.lang.ada:27264 Date: 2002-07-20T04:59:40+00:00 List-Id: On 21 Jun 2002 04:45:08 -0700, dewar@gnat.com (Robert Dewar) wrote: >Robert A Duff wrote in message news:... >> "chris.danx" 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)