comp.lang.ada
 help / color / mirror / Atom feed
From: "John G. Volan" <johnvolan@sprintmail.com>
Subject: Re: Private declaration question
Date: 1997/06/10
Date: 1997-06-10T00:00:00+00:00	[thread overview]
Message-ID: <339E062E.2BC4@sprintmail.com> (raw)
In-Reply-To: 865993476.33snx@jvdsys.nextjk.stuyts.nl


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? :-) ");
------------------------------------------------------------------------




  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 ` Robert A Duff
1997-06-10  0:00 ` Anonymous
1997-06-10  0:00 ` Dale Stanbrough
1997-06-11  0:00   ` Jerry van Dijk
1997-06-10  0:00     ` John G. Volan [this message]
1997-06-10  0:00       ` John G. Volan
1997-06-10  0:00 ` Stephen Leake
replies disabled

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