comp.lang.ada
 help / color / mirror / Atom feed
From: nobody@REPLAY.COM (Anonymous)
Subject: Re: Private declaration question
Date: 1997/06/10
Date: 1997-06-10T00:00:00+00:00	[thread overview]
Message-ID: <199706101323.PAA26477@basement.replay.com> (raw)
In-Reply-To: 865912531.32snx@jvdsys.nextjk.stuyts.nl


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/




  parent reply	other threads:[~1997-06-10  0:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-06-10  0:00 Private declaration question Jerry van Dijk
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 message]
1997-06-10  0:00 ` Stephen Leake
1997-06-10  0:00 ` Robert A Duff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox