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.8 required=5.0 tests=BAYES_00, BUG6152_INVALID_DATE_TZ_ABSURD,LOTS_OF_MONEY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,6401faa712588412 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-08-17 13:30:02 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!jfk3-feed1.news.digex.net!dca6-feed2.news.digex.net!intermedia!netnews.jhuapl.edu!not-for-mail From: Jonathan DeSena Newsgroups: comp.lang.ada Subject: Re: Access to tagged type parameters Date: Fri, 17 Aug 2001 16:23:02 +0228 Organization: JHU/APL Message-ID: <9ljud5$ck8$1@houston.jhuapl.edu> References: <9lje36$ijn$1@houston.jhuapl.edu> <%def7.5255$2u.51636@www.newsranger.com> NNTP-Posting-Host: desenjt1.jhuapl.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: houston.jhuapl.edu 998079717 12936 128.244.68.35 (17 Aug 2001 20:21:57 GMT) X-Complaints-To: usenet@houston.jhuapl.edu NNTP-Posting-Date: 17 Aug 2001 20:21:57 GMT User-Agent: KNode/0.6.1 Xref: archiver1.google.com comp.lang.ada:12074 Date: 2001-08-17T20:21:57+00:00 List-Id: Ted Dennison wrote: > In article , > David Brown says... >> >>Jonathan DeSena wrote: >> >>> "All formal parameters belonging to tagged >>> types are implicitly declared to be aliased. This allows a subprogram to >>> create access values pointing to its tagged formal parameters using the >>> 'Access attribute ..." (section 12.6.2, page 579 in my version) >>> >>> non-local pointer cannot point to local object >> >>> B_Access: A_Access_Type; >> >>The pointer access type A_Access_Type has a scope outside of the scope of >>the object you getting the access value of. > > Actually, it doesn't though. The actual pointed-to object is B, which is > declared at the same scope as A_Access_Type. > > It looks like the compiler is considering C (the formal parameter) to be > the pointed to object instead of B (the actual parameter). I guess it can > do that, but then I don't much see the point of the rule specifying that > tagged types are always passed by reference. By this rule a tagged > by-value pointer would be just as safe (and useful). I guess it still has > use for 'Unchecked_Access... > > FWIW, GreenHills tags the same line with the following error: > LRM:3.10.2(28), The prefix to 'ACCESS shall not be statically deeper than > that of the expected type, Continuing > So, does that mean the original quote is incorrect, or just that some compilers do not impliment it correctly? >>If you use 'Unchecked_Access, >>you will get the access you want, however, the it is up to you to make >>sure it doesn't go outside of scope. > > Another possibility is to use the "access" parameter mode instead of "in > out". In that case, the accessability rules seem to behave as I would > expect. Unfortunately, the reason I want to do this is to be able to add the passed in tagged type, say type A_Type, to a routine which will add it's access value to an array of access values, say A_Access_Type. Thus I WANT to be able to do the equivalent of the assignment B_Access := B'Access. If B is type access to A_Type'Class, I cannot do B_Access:=B, or something. On the otherhand, if I use the type A_Access_Type as the paramater instead, the assignment B_Access:=B works (since B & B_Access are now the same type), but the routine is not inhereted to derived types of A_Type. This means that it is very difficult to use tagged types AND access types together and still take advantage of inheritance. (Does that paragraph make any sense, or do I need to clarify? It now seems unwieldy to me. Oh well) I suppose 'Unchecked_Access might do the trick, but I don't know enough to know where the pitfalls of using it are. Also, this seems overly complicated just because of using a tagged type. I tried to remove as many access types as possible to simplify matters, but because I am using a recursive type, they are required (won't compile without them). Because of Ada's strong typing (a good thing, I agree), once I use access types, they seem to proliferate throughout the package. Thanks again, jtd