From: Jonathan DeSena <jonathan.desena@jhuapl.edu>
Subject: Re: Access to tagged type parameters
Date: Fri, 17 Aug 2001 16:23:02 +0228
Date: 2001-08-17T20:21:57+00:00 [thread overview]
Message-ID: <9ljud5$ck8$1@houston.jhuapl.edu> (raw)
In-Reply-To: %def7.5255$2u.51636@www.newsranger.com
Ted Dennison wrote:
> In article <pybf7.17453$ZM2.1548231@newsread2.prod.itd.earthlink.net>,
> David Brown says...
>>
>>Jonathan DeSena <jonathan.desena@jhuapl.edu> 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
next prev parent reply other threads:[~2001-08-17 13:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-08-17 9:16 Access to tagged type parameters Jonathan DeSena
2001-08-17 16:23 ` David Brown
2001-08-17 19:26 ` Ted Dennison
2001-08-17 13:55 ` Jonathan DeSena [this message]
2001-08-17 21:51 ` Ted Dennison
2001-08-20 14:03 ` Jonathan DeSena
2001-08-17 21:45 ` tmoran
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox