comp.lang.ada
 help / color / mirror / Atom feed
From: Pascal MALAISE <malaise@magic.fr>
Subject: Re: Storage_Error with parameterized records
Date: 1998/07/04
Date: 1998-07-03T22:19:44+00:00	[thread overview]
Message-ID: <359D5900.3CC0D569@magic.fr> (raw)
In-Reply-To: 359D3A0C.13AF4C53@cl.cam.ac.uk


Let's take the place of the compiler.

>  type CMatrix is
>      array (Natural range <>, Natural range <>) of ...

You want un unconstrained mattrix, fair enough, each dimention between 0
and
integer'last. So far, it's just a type. So far so good.


>   type Correlation_Matrix(Last_Line : Natural := 0) is
>      record
>         Mat : CMatrix(0 .. Last_Line, 0 .. Last_Line);
>      end record;
It's just a type. No problem so far.
I think you get the compiler warning (and the exception) when you
declare an object of type Correlation_Matrix.

You want a mutant object containing the mattrix. The rule is (often), in
order to allow you to "mute" your object's last_line from 0 to 
integer'last, to allocate the maximum size -> integer'last *
integer'last floats!


So, when you use mutants, use a "reasonable" subtype.


   subtype Correlation_Coefficient is Float;
   subtype Reasonable_Range is Natural range 0 .. 100;

   type CMatrix is
      array (Reasonable_Range range <>, Reasonable_Range range <>) of
        Correlation_Coefficient;

   type Correlation_Matrix(Last_Line : Reasonable_Range := 0) is
      record
         Mat : CMatrix(0 .. Last_Line, 0 .. Last_Line);
      end record;
Then, when you declare the object, the compiler allocates 100*100
floats.

You can be thankfull to your the compiler for warning you at compile
time.
Not all of the do so  :-)

--
Pascal MALAISE		| E-mail:
22 Avenue de CHOISY	|  (priv) malaise@magic.fr
75013 PARIS		|  (prof) malaise@fr.airsysatm.thomson-csf.com
FRANCE




  reply	other threads:[~1998-07-04  0:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-07-03  0:00 Storage_Error with parameterized records Markus Kuhn
1998-07-04  0:00 ` Pascal MALAISE [this message]
1998-07-05  0:00 ` david.c.hoos.sr
1998-07-08  0:00   ` Robert A Duff
1998-07-08  0:00     ` Robert Dewar
     [not found] ` <dewar.899586342@merv>
     [not found]   ` <359F50D9.5126DEE1@cl.cam.ac.uk>
1998-07-07  0:00     ` Robert Dewar
1998-07-10  0:00 ` Samuel Mize
1998-07-13  0:00   ` Robert Dewar
replies disabled

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