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-20 10:48:14 PST Newsgroups: comp.lang.ada 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!news-out.visi.com!hermes.visi.com!uunet!ash.uu.net!world!news From: Robert A Duff Subject: Re: have to use unrestricted access but just what about access Sender: news@world.std.com (Mr Usenet Himself) Message-ID: Date: Sat, 20 Jul 2002 17:47:07 GMT References: <0x8Q8.6779$ZP1.1263481@news11-gui.server.ntli.net> <5ee5b646.0206210345.2d58d8e0@posting.google.com> NNTP-Posting-Host: shell01.theworld.com Organization: The World Public Access UNIX, Brookline, MA X-Newsreader: Gnus v5.7/Emacs 20.7 Xref: archiver1.google.com comp.lang.ada:27276 Date: 2002-07-20T17:47:07+00:00 List-Id: Craig Carey 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)