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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, WEIRD_PORT autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9da5d24e17589a88 X-Google-Attributes: gid103376,public Path: controlnews3.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!nnx.oleane.net!oleane!freenix!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: type extension at deeper accessibility level than parent Date: 04 May 2004 14:35:56 -0400 Organization: Cuivre, Argent, Or Message-ID: References: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: melchior.cuivre.fr.eu.org 1083695768 23691 212.85.156.195 (4 May 2004 18:36:08 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Tue, 4 May 2004 18:36:08 +0000 (UTC) To: comp.lang.ada@ada-france.org Return-Path: In-Reply-To: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 X-Virus-Scanned: by amavisd-new-20030616-p7 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: controlnews3.google.com comp.lang.ada:249 Date: 2004-05-04T14:35:56-04:00 Xaelis 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