* Private declaration question @ 1997-06-10 0:00 Jerry van Dijk 1997-06-10 0:00 ` Robert A Duff ` (3 more replies) 0 siblings, 4 replies; 8+ messages in thread From: Jerry van Dijk @ 1997-06-10 0:00 UTC (permalink / raw) 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. -- -- Jerry van Dijk | Leiden, Holland -- Consultant | Team Ada -- Ordina Finance | jdijk@acm.org ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Private declaration question 1997-06-10 0:00 Private declaration question Jerry van Dijk @ 1997-06-10 0:00 ` Robert A Duff 1997-06-10 0:00 ` Stephen Leake ` (2 subsequent siblings) 3 siblings, 0 replies; 8+ messages in thread From: Robert A Duff @ 1997-06-10 0:00 UTC (permalink / raw) In article <865912531.32snx@jvdsys.nextjk.stuyts.nl>, Jerry van Dijk <jerry@jvdsys.nextjk.stuyts.nl> wrote: > 7. type A_Type is array (Positive range <>) of Integer; > | > >>> full view of type must be definite subtype This error message is not saying A_Type must be a full view -- it is, by definition (full view = completion). It is saying A_Type must be definite, which means the size for allocating objects is known. You can make the private type indefinite by adding "(<>)" -- unknown discriminants. Then then the full view can also be indefinite. See 7.3(11-12). - Bob ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Private declaration question 1997-06-10 0:00 Private declaration question Jerry van Dijk 1997-06-10 0:00 ` Robert A Duff @ 1997-06-10 0:00 ` Stephen Leake 1997-06-10 0:00 ` Dale Stanbrough 1997-06-10 0:00 ` Anonymous 3 siblings, 0 replies; 8+ messages in thread From: Stephen Leake @ 1997-06-10 0:00 UTC (permalink / raw) 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Private declaration question 1997-06-10 0:00 Private declaration question Jerry van Dijk 1997-06-10 0:00 ` Robert A Duff 1997-06-10 0:00 ` Stephen Leake @ 1997-06-10 0:00 ` Dale Stanbrough 1997-06-11 0:00 ` Jerry van Dijk 1997-06-10 0:00 ` Anonymous 3 siblings, 1 reply; 8+ messages in thread From: Dale Stanbrough @ 1997-06-10 0:00 UTC (permalink / raw) Jerry van Dijk writes: "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" think what would happen if someone declared... type stuff is array (1..10) of A_Type; Arrays can only be declared using definite (i.e. fixed size) types. Try type A_Type (<>) is limited private; Dale ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Private declaration question 1997-06-10 0:00 ` Dale Stanbrough @ 1997-06-11 0:00 ` Jerry van Dijk 1997-06-10 0:00 ` John G. Volan 0 siblings, 1 reply; 8+ messages in thread From: Jerry van Dijk @ 1997-06-11 0:00 UTC (permalink / raw) In article <5nibkg$p9t$1@goanna.cs.rmit.edu.au> dale@goanna.cs.rmit.EDU.AU writes: > 3. type A_Type is limited private; > 7. type A_Type is array (Positive range <>) of Integer; > | > >>> full view of type must be definite subtype" > >>think what would happen if someone declared... >> >> type stuff is array (1..10) of A_Type; Someone would have a problem :-) >Arrays can only be declared using definite (i.e. fixed size) types. > > type A_Type (<>) is limited private; Ok, but then it fails on type A_type (<>, <>) is limited private; ... private type A_Type is array (Positive range <>, Positive range <>) of Integer; However both GNAT and ObjectAda accept: type A_type (<>) is limited private; ... private type A_Type is array (Positive range <>, Positive range <>) of Integer; but of course fail when trying to create an A_Type object. Any idea's ? -- -- Jerry van Dijk | Leiden, Holland -- Business Consultant | Team Ada -- Ordina Finance | jdijk@acm.org ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Private declaration question 1997-06-11 0:00 ` Jerry van Dijk @ 1997-06-10 0:00 ` John G. Volan 1997-06-10 0:00 ` John G. Volan 0 siblings, 1 reply; 8+ messages in thread From: John G. Volan @ 1997-06-10 0:00 UTC (permalink / raw) Jerry van Dijk wrote: > > However both GNAT and ObjectAda accept: > > type A_type (<>) is limited private; > ... > private > type A_Type is array (Positive range <>, Positive range <>) of Integer; > > but of course fail when trying to create an A_Type object. > > Any idea's ? (1) You can provide one or more functions that return A_Type: type A_Type (<>) is limited private; function Make_A (Length, Width : in Natural; Value : in Integer) return A_Type; ... private type A_Type is array (Positive range <>, Positive range <>) of Integer; which can be implemented as, e.g.: function Make_A (Length, Width : in Natural; Value : in Integer) return A_Type is begin return A_Type (1 .. Length, 1 .. Width)'(others => Value); end Make_A; and which a client can utilize within the initialization of a object declaration, e.g.: Clients_A : A_Type := Make_A (Clients_Length, Clients_Width, Clients_Value); (2) Instead of declaring A_Type with unknown discriminants, give it known discriminants: type A_Type (Length, Width : Natural) is private; ... private type A_Content_Type is array (Positive range <>, Positive range <>) of Integer; type A_Type (Length, Width : Natural) is record Content : A_Content_Type (1 .. Length, 1 .. Width); end record; ------------------------------------------------------------------------ Internet.Usenet.Put_Signature (Name => "John G. Volan", Employer => "Texas Instruments Advanced C3I Systems, San Jose, CA", Work_Email => "johnv@ti.com", Home_Email => "johnvolan@sprintmail.com", Slogan => "Ada95: World's *FIRST* International-Standard OOPL", Disclaimer => "My employer never defined these opinions, so using " & "them would be totally erroneous...or is that just " & "nondeterministic behavior now? :-) "); ------------------------------------------------------------------------ ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Private declaration question 1997-06-10 0:00 ` John G. Volan @ 1997-06-10 0:00 ` John G. Volan 0 siblings, 0 replies; 8+ messages in thread From: John G. Volan @ 1997-06-10 0:00 UTC (permalink / raw) John G. Volan wrote: > > return A_Type (1 .. Length, 1 .. Width)'(others => Value); Woops! That should be: return A_Type'(1 .. Length => (1 .. Width => Value)); ------------------------------------------------------------------------ Internet.Usenet.Put_Signature (Name => "John G. Volan", Employer => "Texas Instruments Advanced C3I Systems, San Jose, CA", Work_Email => "johnv@ti.com", Home_Email => "johnvolan@sprintmail.com", Slogan => "Ada95: World's *FIRST* International-Standard OOPL", Disclaimer => "My employer never defined these opinions, so using " & "them would be totally erroneous...or is that just " & "nondeterministic behavior now? :-) "); ------------------------------------------------------------------------ ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Private declaration question 1997-06-10 0:00 Private declaration question Jerry van Dijk ` (2 preceding siblings ...) 1997-06-10 0:00 ` Dale Stanbrough @ 1997-06-10 0:00 ` Anonymous 3 siblings, 0 replies; 8+ messages in thread From: Anonymous @ 1997-06-10 0:00 UTC (permalink / raw) On Tue, 10 Jun 97 03:15:31 GMT, jerry@jvdsys.nextjk.stuyts.nl (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. > > -- > > -- Jerry van Dijk | Leiden, Holland > -- Consultant | Team Ada > -- Ordina Finance | jdijk@acm.org > > No, the correct ARM reference is 3.3(23): A subtype is an indefinite subtype if it is an unconstrained array subtype, or if it has unknown discriminants or unconstrained discriminants without defaults (see 3.7); otherwise the subtype is a definite subtype (all elementary subtypes are definite subtypes). The problem here is that the language allows a client of Oops to declare and object of type A_Type: Object : Oops.A_Type; However, the full view of the type is an unconstrained array type, and such an object declaration is illegal. It's the same as declaring Object : String; You can't do this; you have to supply a definite subtype, either explicitly subtype Name is String (27 .. 358); Object : Name; or implicitly Object : String (42 .. 71); However, there's no way for the client to know that Oops.A_Type needs constraining, nor to constrain it. You have several choices: 1. Make the private view of Oops.A_Type indefinite by adding the an unknown discriminant: type A_Type (<>) is limited private; 2. Make the full view definite: type A_Type is array (Positive range 1 .. 77) of Integer; 3. Do something else. This covers a lot of territory, including having the full view be a discriminated record type with default discriminants, or having the full view be an extension of Ada.Finalization.Controlled with a component of an access type that designates the unconstrained array type. Jeff Carter PGP:1024/440FBE21 My real e-mail address: ( carter @ innocon . com ) "Now go away, or I shall taunt you a second time." Monty Python & the Holy Grail Posted with Spam Hater - see http://www.compulink.co.uk/~net-services/spam/ ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~1997-06-11 0:00 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 1997-06-10 0:00 Private declaration question Jerry van Dijk 1997-06-10 0:00 ` Robert A Duff 1997-06-10 0:00 ` Stephen Leake 1997-06-10 0:00 ` Dale Stanbrough 1997-06-11 0:00 ` Jerry van Dijk 1997-06-10 0:00 ` John G. Volan 1997-06-10 0:00 ` John G. Volan 1997-06-10 0:00 ` Anonymous
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox