TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Classic View

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

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

Print Reply
Steven Deller <[log in to unmask]>
Thu, 4 Feb 1999 11:00:44 -0800
text/plain (136 lines)
Rick,
For item 1, my compiler tells me that for the following:

package Trial3 is
    type Case_Type is (Open, Shut);
    type Uncon is private;
    procedure Dumb (X : in out Uncon);
private
    type Uncon is array (Positive range <>) of Case_Type;
end Trial3;

" >>> Line 6: type Uncon is array (Positive range <>) of Case_Type"
"*** array (Positive range <>) of Case_Type must be constrained [RM_95
7.3(12)]"

When I read 7.3(12) it states that "..., then the full_type_declaration shall
define a definite subtype" (and a definite subtype requires array bounds).
 That makes sense to me, since if code that used this package declared an
object of type Uncon, there would be no way to determine the array bounds for
that object.

It is possible to use access types for Uncon, such that only the package body
does any actual allocations of array entities, which may satisfy the original
need you had:

package Trial2 is
    type Case_Type is (Open, Shut);
    type Uncon is private;
private
    type Uncon_array is array (Positive range <>) of Case_Type;
    type Uncon is access Uncon_array ;
end Trial2;

It is also possible to defer the definition of the Uncon_array into the body
of the package:

package Trial2 is
    type Case_Type is (Open, Shut);
    type Uncon is private;
    procedure Dumb (X : in out Uncon);
private
    type Uncon_Array;
    type Uncon is access Uncon_Array;
end Trial2;

package body Trial2 is
    type Uncon_Array is array (Positive range <>) of Case_Type;
    procedure Dumb (X : in out Uncon) is
    begin
        if X = null then
            X := new Uncon_Array'(1 => Open, 2 => Shut);
        end if;
    end Dumb;
end Trial2;


For item 2, try the following:

procedure Trial is
    type Case_Type is (Open, Shut);
    type Court_Type is array (Positive range <>) of Case_Type;

    Always_Guilty : constant Court_Type (2 .. 1) := Court_Type'(2 .. 1 =>
Open);

begin  -- Trial
    null;
end Trial;

This compiles and runs with my compiler.

Regards,
Steve

On Thursday, February 04, 1999 12:46 AM, Rick Duley
[SMTP:[log in to unmask]] wrote:
> Hi Teamers,
>
>         Here is a couple of bits of bother with unconstrained arrays which
I
>         have
> been able to resolve neither through the study of the Ada95 LRM, the
> Rationale nor yet any of the texts in our library.
> 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)?
> 2.   Try as I might I can't find a way to define a null constant of an
> unconstrained array type  -  I expected the syntax to run something like
> this:
>
> procedure Trial is
>
>    type Case_Type  is (Open, Shut);
>    type Court_Type is array(Positive range<>) of Case_Type;
>
>    Always_Guilty : constant Court_Type := Court_Type(2 .. 1);
>
> begin  -- Trial
>    null;
> end Trial;
>
>         Unfortunately, my compiler does not share my ambitions and again
the
>         LRM
> is indulging in Information Hiding :) !  I have tried a number of syntax
> variations but all I have been able to achieve is success with a variable
> using:
>
>         Always_Guilty : Court_Type(2 .. 1);
>
> Any and all assistance appreciated.  Thanks.
>
>
>                                     ______
> Rick Duley                         /      \
> Edith Cowan University            (____/\  )
> Perth, Western Australia           |___  U?(____
>                                    _\L.   |      \     ___
> ECU: +61 (08) 9370 6619          / /"""\ /.-'     |   |\  |
> mob: 0416 365 619               ( /  _/u     |    \___|_)_|
>                                  \|  \\      /   / \_(___ __)
>                                   |   \\    /   /  |  |    |
>                                   |    )  _/   /   )  |    |
>                                   _\__/.-'    /___(   |    |
> I think,                       _/  __________/     \  |    |
> Therefore I am...             //  /  (              ) |    |
>                              ( \__|___\    \______ /__|____|
> I Think!                              \    (___\   |______)_/
>                                \   |\   \  \     /
>                                 \  | \__ )  )___/
>                                  \  \  )/  /__(
>                                   ___ |  /_//___|   \_________
>                                _/  ( / OUuuu    \
>                               `----'(____________)

ATOM RSS1 RSS2