comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@acm.org>
To: comp.lang.ada@ada-france.org
Subject: Re: type extension at deeper accessibility level than parent
Date: 04 May 2004 14:35:56 -0400
Date: 2004-05-04T14:35:56-04:00	[thread overview]
Message-ID: <mailman.69.1083695767.313.comp.lang.ada@ada-france.org> (raw)
In-Reply-To: <pan.2004.05.04.09.47.26.650290@nospam.lifl.fr>

Xaelis <Alexis.Muller@nospam.lifl.fr> writes:

> Hi,
> 
> I don't understand why i can't do somthing like that :
> 
> -- a.ads
> 
> package A is
>    type X is abstract tagged null record;
> end A;
> 
> -- b.ads
> 
> with A;
> 
> generic
>    type P is private;
> package B is
>    type Y is new A.X with null record;
> end B;
> 
> --  essai.adb
> 
> with B;
> 
> procedure Essai is
>    package C is new B (Integer);
> begin
>    null;
> end Essai;
> 
> I have :
> essai.adb:4:04: instantiation error at b.ads:6
> essai.adb:4:04: type extension at deeper accessibility level than parent

"accessibility level" here refers to the position of variables and
subprograms on the stack.

A and Essai are "library level"; they are on the heap, not the stack.

Essai.C is one subprogram down; it is not at library level.

> I don't know why is it a problem 

Since package C is declared in a _procedure_, the subprograms it
declares will not exist after the procedure exits (package B doesn't
actually declare any subprograms, but the compiler assumes it will at
some point). Since A.X is a tagged type, at some point the compiler
might try to dispatch thru a global variable of type A.X'class to a
subprogram in Essai.C, which might not exist. So it's illegal.

> and who to solve it. 

Declare package C at library level:

package C si new B (Integer);

with C; use C;
procedure Essai is
begin
   null;
end Essai;

> Thanks for your help.

You're welcome. This is one area where Ada is confusing. But it is an
example of the rules of Ada preventing you from using dangling
pointers. 

-- 
-- Stephe




      parent reply	other threads:[~2004-05-04 18:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-04  9:47 type extension at deeper accessibility level than parent Xaelis
2004-05-04 12:33 ` Martin Krischik
2004-05-04 18:35 ` Stephen Leake [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