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,8a402d78988bdf2b X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-12-23 15:02:46 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-08!supernews.com!newsswitch.lcs.mit.edu!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: [announcement] SYSAPI and SYSSVC for Windows Date: 23 Dec 2003 18:02:45 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: NNTP-Posting-Host: pip1-5.std.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1072220565 613 192.74.137.185 (23 Dec 2003 23:02:45 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Tue, 23 Dec 2003 23:02:45 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: archiver1.google.com comp.lang.ada:3772 Date: 2003-12-23T18:02:45-05:00 List-Id: "Dmitry A. Kazakov" writes: > Ekkehard Morgenstern wrote: > > so I could've just used a tagged limited record? > > > > Like this: > > > > type T is tagged limited > > record > > A : My_Array_Type; > > end record; > > > > procedure F ( O : in out T ) is > > Ptr : My_Array_Cell_Ptr; > > begin > > Ptr := O.A(1)'Access; > > end; > > > > Right? > > No. It is unrelated. The thing you are getting access of has to be aliased. > So it is the array elements which has to be, for example: > > type T is limited private; > private > type Integer_Array is array (Integer range <>) of aliased Integer; > type T is limited record > A : Integer_Array (1..3); > end record; > > procedure F (O : in out T ) is > begin > ... O.A(1)'Access; -- This is OK, A(i) are aliased No, that's not quite good enough. The parameter O is considered to be nested within F, so you need 'Unchecked_Access instead of 'Access here. Whenever you use 'Unchecked_Access, you have to make sure you don't use dangling pointers -- so the & operator in C or C++ is more like 'Unchecked_Access than 'Access in that regard. The point is: when you say 'Access, the compiler can prove that you don't have dangling pointers. Otherwise, you need 'Unchecked_Access (but then you better prove it yourself, or your program might do bad things). > end; > > If the array elements be tagged, then you would need not write "aliased" in > the array declaration. That's not quite right. Tagged *parameters* (like O in the above example) are automatically aliased. But other objects are aliased only if declared so (by the "aliased" keyword) or if allocated in the heap by "new" (whether tagged or not). IMHO, it was a mistake to make tagged parameters automatically aliased. We should, instead, have allowed the "aliased" keyword on parameters. Summary: To get an access value to an existing object, you must first make sure it's aliased (which means allocated on the heap, explicitly declared "aliased", or a tagged parameter). Then you must worry about accessibility level (which determines whether you should use 'Access or 'Unchecked_Access). - Bob