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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,dd41b5654bd378e7 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!q3g2000prf.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Representation item appears too late Date: Thu, 25 Oct 2007 08:41:21 -0700 Organization: http://groups.google.com Message-ID: <1193326881.224163.110410@q3g2000prf.googlegroups.com> References: <87640vgvvl.fsf@ludovic-brenta.org> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1193326881 12971 127.0.0.1 (25 Oct 2007 15:41:21 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 25 Oct 2007 15:41:21 +0000 (UTC) In-Reply-To: <87640vgvvl.fsf@ludovic-brenta.org> User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: q3g2000prf.googlegroups.com; posting-host=66.126.103.122; posting-account=ps2QrAMAAAA6_jCuRt2JEIpn5Otqf_w0 Xref: g2news2.google.com comp.lang.ada:2565 Date: 2007-10-25T08:41:21-07:00 List-Id: On Oct 25, 6:35 am, Ludovic Brenta wrote: > Consider the following declarations: > > package A is > > type Size is (Small, Large); > > type Foo is range 1 .. 8; > > type T is record > A : Boolean; > B : Boolean; > C : Boolean; > D : Size; -- corrected, was Size_Type; > E : Foo; > end record; > > procedure P (X : in T); -- a null procedure for the sake of example > > end A; > > with A; > package B is > > type T is new A.T; > for T use record -- line 5 > A at 0 range 0 .. 0; > B at 0 range 1 .. 1; > C at 0 range 2 .. 2; > D at 0 range 3 .. 3; > E at 0 range 4 .. 7; > end record; > > end B; > > Compiling B with GCC 4.1 I get: > > gcc-4.1 -c -g -O2 -gnatafnoy -gnatVa -gnatwa -I- -gnatA /home/lbrenta/src/ada/b.ads > b.ads:5:04: representation item appears too late > b.ads:5:04: primitive operations already defined for "T" > gnatmake: "/home/lbrenta/src/ada/b.ads" compilation error > > This also happens with GCC 4.2. > > Of course, removing procedure A.P also removes the error but this is > not an option. > > What should I do to specify a representation clause? Do I have to > resort to declaring a mirror type in B? Why? The error message you're getting isn't very helpful. What you're trying to do is explicitly forbidden by 13.1(10): ================================================================= (10) For an untagged derived type, no type-related representation items are allowed if the parent type is a by-reference type, or has any user-defined primitive subprograms. (AARM 10.b) Reason: ... The reason for forbidding type-related representation items on untagged types with user-defined primitive subprograms was to prevent implicit change of representation for type- related aspects of representation upon calling inherited subprograms, because such changes of representation are likely to be expensive at run time. ... ================================================================= > Thanks for any advice. You could declare T in an inner package of A, then right after that inner package say "subtype T is Inner.T;". The result would be that P would not be a primitive subprogram. It also wouldn't be inherited when B.T is declared---i.e. B.P would not exist unless you declare it yourself. That might work---but I don't know if there are any other consequences elsewhere in your program to defining T in an inner package. Another possibility would be to put P in an inner package inside A, which would again make it not primitive (and not inherited). Of course, that would require all the references to P elsewhere in the program to change. And you couldn't have a renaming of Inner.P outside the inner package, because the renaming would become a primitive subprogram of T and you'd end up with the same problem. -- Adam