comp.lang.ada
 help / color / mirror / Atom feed
From: Jacob Sparre Andersen <sparre@nbi.dk>
Subject: Problem with generic parameter
Date: 22 Jun 2005 12:21:10 +0200
Date: 2005-06-22T12:21:10+02:00	[thread overview]
Message-ID: <m2acli7kvd.fsf@hugin.crs4.it> (raw)

When I try to compile the program included below (cut down version of
a test program) GNAT 3.15p reports:

-----
Compiling: demo.adb (source file time stamp: 2005-06-22 10:10:41)

    16.                               Measurement_Array => Measurement_Array);
                                                           |
        >>> component subtype of actual does not match that of formal "Measurement_Array"
        >>> instantiation abandoned

 20 lines: 2 errors
-----

I can't see _how_ it doesn't match.  Can somebody figure out what I'm
doing wrong?  And maybe even suggest me an elegant solution to the
problem?

The reason I have Measurement_Array as a generic parameter is that I
also use it elsewhere, and that I may want to work with differently
indexed measurement arrays.  Does it - despite that - make more sense
to declare the types "Measurement" and "Measurement_Array" together?

/Jacob

------------------------------------------------------------------------------
--  Source code:

with Generic_Root;
with Generic_Root.Child;

procedure Demo is

   type Scalar is digits 15;

   package Measurements is
      new Generic_Root (Scalar => Scalar);

   type Measurement_Array is array (Positive range <>)
     of Measurements.Measurement;

   package Measurement_Text_IO is
      new Measurements.Child (Indices           => Positive,
                              Measurement_Array => Measurement_Array);

begin
   null;
end Demo;

generic

   type Scalar is digits <>;

package Generic_Root is

   ---------------------------------------------------------------------------
   --  type Limit:

   type Limit is (Below, Exact, Above, Undefined);

   ---------------------------------------------------------------------------
   --  type Measurement:

   type Measurement (As : Limit := Exact) is
      record
         case As is
            when Below | Exact | Above =>
               Value : Scalar;
            when Undefined =>
               null;
         end case;
      end record;

   ---------------------------------------------------------------------------

end Generic_Root;

with Ada.Text_IO;

generic

   type Indices is (<>);

   type Measurement_Array is array (Indices range <>) of Measurement;

package Generic_Root.Child is

end Generic_Root.Child;



             reply	other threads:[~2005-06-22 10:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-22 10:21 Jacob Sparre Andersen [this message]
2005-06-22 11:16 ` Problem with generic parameter Martin Dowie
2005-06-22 11:58 ` Marius Amado Alves
2005-06-22 13:09   ` Jacob Sparre Andersen
2005-06-22 14:26     ` Marius Amado Alves
     [not found] ` <f6af3631a69872fe2f46258f86b08473@netcabo.pt>
2005-06-22 12:43   ` Marius Amado Alves
replies disabled

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