Ada0Y limited with

Ada0Y limited with

Post by Wojtek Nar » Sat, 02 Oct 2004 07:23:46


(GNAT in gcc mainline refuses compile the example from the "An invitation
to Ada 2005" presentation, claiming "circular unit dependency" error, so
I have serious problems trying to understand how this is supposed to work.)

Do I need to declare an access type every time I want to use a a type from
the limited-withed package, or can I just use the access type declared in
the limited-withed package?

Which of the following is code illegal?

with Parts;
package Whole is

type Whole_Type is record
Part : Parts.Part_Type;
end record;

type Whole_Access is access all Whole_Type;

end Whole;

limited with Whole;
package Parts is

type Part_Type is record
Prev : Whole.Whole_Access;
Next : access Whole.Whole_Type;
end record;

end Parts;


Ada0Y limited with

Post by Randy Bruk » Sat, 02 Oct 2004 08:40:36


Limited with always gives you an incomplete view of any types, so that
clearly applies to Whole_Access as well.

The reason for expanding the use of anonymous access types is to avoid the
junk conversions needed if you define named access types everywhere that you
use limited withed packages.

So, component Prev is wrong; it should look like component Next.

Randy Brukardt.


Ada0Y limited with

Post by Wojtek Nar » Sat, 02 Oct 2004 16:52:23

But then it will not be legal to assign 'Whole.Whole_Access' to 'access
Whole_Type' members?

Thank you,

Ada0Y limited with

Post by Randy Bruk » Sun, 03 Oct 2004 03:30:45

It is legal; named access types implicitly convert to anonymous access types
as needed. (See 8.6(25)). That's even true in Ada 95, although the rule has
been broadened for Ada 2005.

To go to the named type from the anonymous one, you'd need a type

But you may not need the named type at all, since anonymous types can be
used in almost all contexts.


Ada0Y limited with

Post by Wojtek Nar » Sun, 03 Oct 2004 03:51:00


Great. Now I am really looking forward to those cool features.

Thank you for your answer. For all your answers.