comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <jeffrey.carter@boeing.com>
Subject: Re: Direct_IO problem -- generic package problem
Date: Thu, 12 Jul 2001 16:58:10 GMT
Date: 2001-07-12T16:58:10+00:00	[thread overview]
Message-ID: <3B4DD722.EB6F3AB7@boeing.com> (raw)
In-Reply-To: 9ijobe$qb4$1@mercur.foa.se

In Ada 83, you could say

generic -- Example
   type T is limited private;
package Example is
   ...
end Example;

and then, before supplying a body for Example, write something like

package P is new Example (T => String);

Then you could supply a body for example that creates a variable of type
T:

package body Example is
   V : T;
   ...
end Example;

This is the same as writing

   V : String;

which is clearly illegal. This would be caught eventually, but was a
"gotcha" that was removed in Ada 95. Now the generic formal type as
given means that it must be possible to declare a variable of the type
(the type must be "definite"). The new generic formal syntax

type T (<>) is [limited] private;

allows the generic to be instantiated with an indefinite type, but means
the generic cannot declare any uninitialized objects of the type.

Ada.Direct_IO declares the generic formal type

type Element_Type is private;

so the type used to instantiate Direct_IO must be definite, while your
type Matrix is indefinite. You have a few possibilities

Use a subtype in place of Small_Nat with a small enough range that you
can provide defaults for all discriminants without encountering
Storage_Error if you declare an unconstrained variable.

Instantiate Direct_IO with constrained subtypes of Matrix for the types
of interest.

Good luck.

-- 
Jeffrey Carter



  parent reply	other threads:[~2001-07-12 16:58 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-12  8:42 Direct_IO problem -- generic package problem Magnus Sparf
2001-07-12  9:19 ` nicolas
2001-07-12 11:38   ` David C. Hoos, Sr.
2001-07-12 12:14     ` nicolas
2001-07-12 11:41   ` Magnus Sparf
2001-07-12 12:25     ` nicolas
2001-07-12 11:33 ` David C. Hoos, Sr.
2001-07-12 16:58 ` Jeffrey Carter [this message]
2001-07-12 19:23   ` tmoran
2001-07-13  8:16     ` Magnus Sparf
replies disabled

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