From: dommo1234@my-deja.com
Subject: Re: Generic type parameters
Date: 1999/06/15
Date: 1999-06-15T00:00:00+00:00 [thread overview]
Message-ID: <7k5t3l$pp9$1@nnrp1.deja.com> (raw)
In-Reply-To: m37lp6cm5h.fsf@mheaney.ni.net
In article <m37lp6cm5h.fsf@mheaney.ni.net>,
Matthew Heaney <matthew_heaney@acm.org> wrote:
>
>
> I don't know about "neater," but you can create another generic
package
> in which to declare the access types, and import an instantiation of
> that package as a generic formal package:
>
> generic
> type TypeX is private;
> package TypeX_Access_Types_G is
>
> type TypeX_A is access all TypeX;
>
> type TypeX_AC is access constant TypeX;
>
> end;
>
> with TypeX_Access_Types_G;
>
> generic
>
> with package TypeX_Access_Types is
> new TypeX_Access_Types_G (<>);
>
> use TypeX_Access_Types;
>
> package Example is
>
> <as above>
>
> end;
>
I think this is quite neat, but having done some experimentation, I''ve
hit another problem that seems to relate to accesibility levels, a
subject that I find very confusing. Here's my test program :-
generic
type TypeX is private;
package TestGeneric is
type TypeX_A is access all TypeX;
type TypeX_AC is access constant TypeX;
end TestGeneric;
with TestGeneric;
generic
type TypeX is private;
package OtherGeneric is
package TypeXAccessTypes is new TestGeneric(TypeX);
use TypeXAccessTypes;
type TestType is
record
variable: aliased TypeX;
end record;
function returnNonConst(aa: access TestType) return TypeX_A;
end OtherGeneric;
package body OtherGeneric is
function returnNonConst(aa: access TestType) return TypeX_A is
begin
-- The following causes a Program_Error at runtime
-- unless an Unchecked_Access is passed in!!!
return aa.variable'Access;
end returnNonConst;
end OtherGeneric;
with OtherGeneric; package OthGenInst is new OtherGeneric(Integer);
with OthGenInst; use OthGenInst;
procedure Main is
testVar2: aliased TestType;
begin
returnNonConst(testVar2'Access).all := 6; -- ERROR!
returnNonConst(testVar2'Unchecked_Access).all := 6; -- OK!
end Main;
Can someone explain exactly what accessibility levels for testVar2,
tsetVar2.variable etc. are in the various scopes so I can understand
the rules better ...
Thanks,
Dom.
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
prev parent reply other threads:[~1999-06-15 0:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-06-14 0:00 Generic type parameters dommo1234
1999-06-15 0:00 ` Matthew Heaney
1999-06-15 0:00 ` dommo1234 [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox