TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy


Options: Use Classic View

Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Topic: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Samuel Mize <[log in to unmask]>
Thu, 4 Feb 1999 09:18:27 -0600
text/plain (59 lines)
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

    package A is
      type A_Type is 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;

        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.

Sam Mize

Samuel Mize -- [log in to unmask] (home email) -- Team Ada
Fight Spam: see \\\ Smert Spamonam