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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a78361b1fb8b4be9,start X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: Instantiation before body seen Date: 1998/01/08 Message-ID: #1/1 X-Deja-AN: 314222757 Content-Transfer-Encoding: 8bit References: <01bd1c95$ddeacf60$LocalHost@----> Content-Type: text/plain; charset=ISO-8859-1 Organization: Estormza Software Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1998-01-08T00:00:00+00:00 List-Id: In article <01bd1c95$ddeacf60$LocalHost@---->, "Dmitriy Anisimkov" wrote: >Compilation of my package by GNAT-3-10 > >-------------------------------- >package AnyPackage > .................. >private generic > with function Compare(C1,C2 : Comp) return Boolean; >function Compare(R1,R2 : TRational) return Boolean; > >function "<" is new Compare("<"); >function ">" is new Compare(">"); >function "<=" is new Compare("<="); >function ">=" is new Compare(">="); >function "=" is new Compare("="); > .................. >end AnyPackage >---------------------- > >causes warning >'cannot instantiate "AnyMyFunction" before body seen' >I have defined body later. > >Is there GNAT limitation or language limitation ? Language "feature." The specification of AnyPackage has to elaborate prior to its body. Therefore there's no way to instaniate Compare in the spec, because its body is in the body of AnyPackage, which hasn't elaborated yet. What code would be "filled in" if you were able to instantiate Compare in the spec, if the template from which that code derives doesn't "exist" yet? What you can do is declare a function specification, and then use an instantiation of Compare as the body of that declaration, via a renames clause. Something like: package AnyPackage is function "=" (L, R : TRational) return Boolean; ... end; package body AnyPackage is generic ... function Compare (...) return Boolean; function Compare (...) return Boolean is ... end Compare; function Is_Equal is new Compare ("="); -- recursive??? function "=" (L, R : TRational) return Boolean renames Is_Equal; ... end; Note that even in the body of the package, the body of Compare must precede any instantiations, or you'll get Program_Error. GNAT is nicely warning you in advance that that's what will happen. -------------------------------------------------------------------- Matthew Heaney Software Development Consultant (818) 985-1271