Mime-Version:
1.0
Date:
Thu, 4 Feb 1999 11:23:58 -0500
Content-Transfer-Encoding:
7bit
Content-Type:
text/plain; charset="iso-8859-1"
|
You can declare a private type with an "unknown discriminant part". The
following example compiles and runs (I tried it under Aonix ObjectAda
7.1.2):
---
package P is
type T(<>) is private;
function F(N : Integer) return T;
private
type T is array(Positive range <>) of Integer;
end P;
package body P is
function F(N : Integer) return T is
begin
return T'(1..N => 0);
end F;
end P;
with P; use P;
procedure Test_Unconstrained is
X : T := F(10);
begin
null;
end Test_Unconstrained;
---
Regards,
Ben Brosgol
Aonix
[log in to unmask]
-----Original Message-----
>From: Samuel Mize <[log in to unmask]>
To: [log in to unmask] <[log in to unmask]>
Date: Thursday, February 04, 1999 10:32 AM
Subject: Re: Problems with unconstrained arrays
>Rick Duley wrote:
>
>> 1. It doesn't appear to be possible to compile the declaration of an
>> unconstrained type as either private or limited private. I haven't been
>> able to find a prohibition of this in the LRM. Is this a compiler
problem
>> (GNAT 3.1)?
>
>I can't cite ARM chapter/verse, but I can see that this can't be done.
>The problem is that you could then try to declare a variable of the
>private type, but there's no way to give it its array bounds. For
>instance:
>
> package A is
> type A_Type is private;
> private
> type A_Type is array (integer range <>) of Integer;
> end A;
>
> -----
> with A;
> procedure Uses_A is
> My_A_Type: A.A_Type; -- what are the array bounds?
> ...
>
>One solution is to have the bounds (or just the upper bound) be
>discriminants to the private type. This will force you to use a
>record type for the full view:
>
> package A is
> type A_Type (Count: Integer) is private;
>
> private
> type Int_Array is array (Integer range <>) of Integer;
>
> type A_Type (Count: integer) is record
> A_Field: Int_Array (1..Count);
> end record;
> end a;
>
>You could also have A_Type be an access to objects of type
>Int_Array. That way you wouldn't need to have the array
>bounds be part of the public view.
>
>If this doesn't fill the bill, you may have to rethink your data
>design. I'm not sure how you intend to use a private but
>unconstrained type.
>
>For chapter and verse, I suspect you should be checking for references
>about unconstrained or indefinite types.
>
>I hope this helps.
>
>Best,
>Sam Mize
>
>--
>Samuel Mize -- [log in to unmask] (home email) -- Team Ada
>Fight Spam: see http://www.cauce.org/ \\\ Smert Spamonam
>
|
|
|