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.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,be018246a766b23 X-Google-Attributes: gid103376,public From: Stephen Leake Subject: Re: Private declaration question Date: 1997/06/10 Message-ID: <339D5973.3953@gsfc.nasa.gov>#1/1 X-Deja-AN: 247459800 References: <865912531.32snx@jvdsys.nextjk.stuyts.nl> Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA Reply-To: Stephen.Leake@gsfc.nasa.gov Newsgroups: comp.lang.ada Date: 1997-06-10T00:00:00+00:00 List-Id: Jerry van Dijk wrote: > > Why has the completion of a private declaration to be a full view ? > > 1. package Oops is > 2. > 3. type A_Type is limited private; > 4. > 5. private > 6. > 7. type A_Type is array (Positive range <>) of Integer; > | > >>> full view of type must be definite subtype > > After browsing the RM I think the error message comes from rule > 7.3(4). If that is true, why is this ? It seems a logical construction > to protect A_Type objects from user interference. Actually, the error is due to RM 7.3(12); the partial view of A_Type has no discriminants, so the full view must be a definite subtype. A definite subtype has a known size; an unconstrained array is not a definite subtype (as the error message says). The reason is that the compiler must know how much memory to allocate when a user of A_Type declares an object: My_Object : Oops.A_Type; Oops provides no way to set the size of the array. The only way to fix this, while keeping A_Type limited, is to provide a discriminant: package Oops is type A_Type (Size : Positive) is limited private; private type Array_Type is array (Positive range <>) of Integer; type A_Type (Size : Positive) is record Contents : Array_Type (1 .. Size); end record; end Oops; Now the user can declare an object: A : Oops.A_Type (2); If A_Type does not need to be limited, you can set the size by returning a value from an initialization function: package Oops is type A_Type (<>) is private; function Init (Size : in Positive) return A_Type; private type A_Type is array (Positive range <>) of Integer; end Oops; package body Oops is function Init (Size : in Positive) return A_Type is begin return (1 .. Size => 0); end Init; end Oops; A : Oops.A_Type := Oops.Init (2); -- - Stephe