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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,9cff4fb5d12e1f68,start X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!a70g2000hsh.googlegroups.com!not-for-mail From: mockturtle Newsgroups: comp.lang.ada Subject: Primitive curiosity... Date: Wed, 17 Sep 2008 13:29:55 -0700 (PDT) Organization: http://groups.google.com Message-ID: <447b8b2a-b7bb-4ff5-89bf-a6b7eecc054e@a70g2000hsh.googlegroups.com> NNTP-Posting-Host: 62.101.126.216 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1221683396 15719 127.0.0.1 (17 Sep 2008 20:29:56 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 17 Sep 2008 20:29:56 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: a70g2000hsh.googlegroups.com; posting-host=62.101.126.216; posting-account=9fwclgkAAAD6oQ5usUYhee1l39geVY99 User-Agent: G2/1.0 X-HTTP-UserAgent: Opera/9.52 (X11; Linux i686; U; en),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:2032 Date: 2008-09-17T13:29:55-07:00 List-Id: Dear *, I was doing some experiments with dispatching operations and I discovered something that made me curious... Consider the following 3-file set: 1 package (base.ad?) with a "root" abstract type (Root) and two derived types (Derived_1 and Derived_2) and 1 "main" (test_bas.adb) ----------------------- Filename : base.ads ---------------- package Base is type Root is abstract tagged null record; -- Uncomment LINE A or LINE B, but not both -- === LINE A === -- procedure Print(X : Root) is abstract; type Derived_1 is new Root with record A : Integer; end record; type Derived_2 is new Root with record B : Float; end record; -- === LINE B === -- procedure Print(X : Root) is abstract; procedure Print(X : Derived_1); procedure Print(X : Derived_2); end Base; ------------------ Filename : base.adb ---------------------- with Ada.Text_Io; package body Base is procedure Print(X : Derived_1) is begin Ada.Text_Io.Put_Line ("[1] " & Integer'Image(X.A)); end Print; procedure Print(X : Derived_2) is begin Ada.Text_Io.Put_Line ("[2] " & Float'Image(X.B)); end Print; end Base; ------------------------------------------------------------- ----------------- Filename : test_base.adb ----------- ------------------------------------------------------------- with Base; procedure Test_Base is function Gimme (X : Boolean) return Base.Root'Class is begin if (X) then return Base.Derived_1'(A => 42); else return Base.Derived_2'(B => 3.1415); end if; end Gimme; begin Base.Print(Gimme(True)); Base.Print(Gimme(False)); end Test_Base; -------------------------------------------------------------------- -------------------------------------------------------------------- -------------------------------------------------------------------- The idea is that the first line in Test_Base should call Print of Derived_1 and the second line should call procedure Print of Derived_2. In order to compile, one must uncomment LINE A or LINE B (but not both) in base.ads. Now the fun bit comes 1) If I uncomment LINE A everything is fine, but... 2) if I uncomment LINE B gcc (4.1.3) complaints with .... other lines .... base.ads:19:14: this primitive operation is declared too late I interpreted the "immediately within" in the sentence [AARM05 3.2.3(2/6)] "The primitive subprograms of a specific type are defined as follows: [...] * For a specific type declared immediately within a package_specification, any subprograms (in addition to the enumeration literals) that are explicitly declared _immediately_within_ the same package_specification and that operate on the type;" as "declared in the same file as the type", but according to the behaviour described above (and some other experiments) it seems that there is a further constraint "before the declaration of any derived type." Is this actually implied by the RM description or is gcc being strict? (Maybe "immediately within" was given a technical sense, but I was not able to find the definition) Why this? There is some deep technical reason or is it just to enforce the programmer to be "order" and declare primitive subprograms close to the type definition? Thank you in advance