From: Adam Beneschan <adam@irvine.com>
Subject: Re: Representation item appears too late
Date: Thu, 25 Oct 2007 08:41:21 -0700
Date: 2007-10-25T08:41:21-07:00 [thread overview]
Message-ID: <1193326881.224163.110410@q3g2000prf.googlegroups.com> (raw)
In-Reply-To: <87640vgvvl.fsf@ludovic-brenta.org>
On Oct 25, 6:35 am, Ludovic Brenta <ludo...@ludovic-brenta.org> 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
next prev parent reply other threads:[~2007-10-25 15:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-25 13:35 Representation item appears too late Ludovic Brenta
2007-10-25 13:46 ` Lucretia
2007-10-25 15:41 ` Adam Beneschan [this message]
2007-10-25 18:37 ` Ludovic Brenta
2007-10-26 4:08 ` Vincent Marciante
2007-10-26 8:34 ` Ludovic Brenta
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox