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 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-20 13:40: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: Mon, 20 Aug 2001 16:31:18 +0228 Organization: JHU/APL Message-ID: <9lrs0f$e6l$1@houston.jhuapl.edu> References: <9lje36$ijn$1@houston.jhuapl.edu> <%def7.5255$2u.51636@www.newsranger.com> <9ljud5$ck8$1@houston.jhuapl.edu> 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 998339407 14549 128.244.68.35 (20 Aug 2001 20:30:07 GMT) X-Complaints-To: usenet@houston.jhuapl.edu NNTP-Posting-Date: 20 Aug 2001 20:30:07 GMT User-Agent: KNode/0.6.1 Xref: archiver1.google.com comp.lang.ada:12139 Date: 2001-08-20T20:30:07+00:00 List-Id: Ted Dennison wrote: > In article <9ljud5$ck8$1@houston.jhuapl.edu>, Jonathan DeSena says... >> >>Ted Dennison wrote: >>> 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? > > I think the Gnat compiler is catching the same error for the same reason, > but is attempting to give it a short understandable message, rather than > refer you to one of the most obtuse sections of the LRM. > > What I'm not sure about is *why* this is illegal, but if two compilers > based on two very different front ends flag it, I suspect it is a > perfectly valid error. Hopefully a good language-lawyer can come and > explain it for us... > >>> 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 > > That's fine. You'd just change the parameter type to "access", the > assignment to "B_Access := A_Access_Type(B);", the procedure call to > "A_Test(C'Access);", and add an "aliased" to the declaration of B. I tried > that with Gnat and it compiled and ran successfully. Ahhh. This does what I want. I had forgotten about type conversions. Actually, it is interesting that you can pass an argument of type A_Access_Type to a subprogram expecting "access to A_Type," but the converse is illegal; also, you can't equate or assign two variables of these two types. > >>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. > > Since its totally unchecked, the pitfals are the ones you were willing to > accept when you tried to do the assignment in the first place: There is no > guarantee that the object that it points to will exist, unless you have > structured your code in such a way as to ensure it. If you find that you > need Unchecked_Access, you should certianly take a step back and see if > that is the case. But you shouldn't shy away from using it entirely, any > more than a C user would shy away from using "&" entirely. Sometimes it is > nessecary. > >>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. > > If you want to create hetrogenious data structures for dynamic > disptaching, they are required. That's kind of an unfortunate departure > from Ada's philosophy of never requiring pointers, but there it is. > Thanks to all. I was getting very frustrated, but I am better now :) jtd