comp.lang.ada
 help / color / mirror / Atom feed
* What is wrong here? (Generic and controlled types)
@ 2000-04-03  0:00 Alexander Boucke
  2000-04-03  0:00 ` Ted Dennison
  0 siblings, 1 reply; 25+ messages in thread
From: Alexander Boucke @ 2000-04-03  0:00 UTC (permalink / raw)


Hello!

I am writing a vector-package using controlled types. 
I implemented some sort of reference-counting to access 
the arrays. This is why I used the controlled types and 
do not access the arrays directly. A non-generic version 
of the packge is running fine and giving good 
improvements in speed and memory-usage against the 
"trivial" implementation. 

While converting the package to be generic I encounter 
an error while compiling my test-program. I must admit, 
that my routine using Ada is not very big yet, so I 
did not find the cause for the error. Here comes a bit 
of code and the error gnat3.12p reports on my HP-UX 10.20:

-----
with Ada.Finalization;
with Unchecked_Deallocation;

generic

   type Real is private;
   type Index is (<>);
   Zero : in Real;

package Generic_Vectors is

   type Vector is new Ada.Finalization.Controlled with private;

private

   Variable_Counter : Natural := 0;
   Object_Counter : Natural := 0;

   type Value_Vector is array (Index range <>) of Real;

   type Handled_Vector(First,Last: Index) is
      record
         Value : Value_Vector(First..Last);
         Count : Natural := 1;
         Object_No : Natural;
      end record;

   type Handled_Vector_Access is access Handled_Vector;

   type Vector is new Ada.Finalization.Controlled with
      record
         Variable_Id : Natural := 0;
         The_Vector : Handled_Vector_Access := null;
      end record;

end Generic_Vectors;
---
In the test-program:

   type Real is digits 10;
   subtype Index is Integer;
   Zero: constant Real := 0.0;

   package Real_Vectors is new Generic_Vectors(Real, Index, Zero);

Of course there are more things around these lines...

gnat reports while compiling:
    29.    package Real_Vectors is new Generic_Vectors(Real, Index, Zero);
           |
        >>> instantiation error at generic_vectors.ads:23
        >>> controlled type must be declared at the library level
        >>> instantiation error at generic_vectors.ads:75
        >>> controlled type must be declared at the library level

Lines 23 and 75 are the lines defining the type Vector.

It would be nice if anybody could point where to find the
solution for doing it right.

Kind regards,

Alexander Boucke
-- 
"I try to write idiot proof code, but they keep making better idiots."

A. Stanley in comp.sys.sgi.admin




^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2000-04-22  0:00 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-04-03  0:00 What is wrong here? (Generic and controlled types) Alexander Boucke
2000-04-03  0:00 ` Ted Dennison
2000-04-03  0:00   ` Robert Dewar
2000-04-03  0:00     ` Florian Weimer
2000-04-03  0:00       ` tmoran
2000-04-04  0:00       ` Alexander Boucke
2000-04-06  0:00       ` Robert Dewar
2000-04-21  0:00         ` Florian Weimer
2000-04-03  0:00     ` swhalen
2000-04-06  0:00       ` Robert Dewar
2000-04-03  0:00     ` Ted Dennison
2000-04-04  0:00     ` Robert A Duff
2000-04-06  0:00       ` Robert Dewar
2000-04-06  0:00       ` Mats Weber
2000-04-06  0:00         ` Robert Dewar
2000-04-06  0:00           ` Robert A Duff
2000-04-06  0:00             ` Robert Dewar
2000-04-21  0:00     ` Vincent Marciante
2000-04-21  0:00       ` Robert Dewar
2000-04-21  0:00         ` Robert Dewar
2000-04-22  0:00         ` Vincent Marciante
2000-04-22  0:00           ` Robert Dewar
2000-04-03  0:00   ` Ehud Lamm
2000-04-04  0:00   ` Alexander Boucke
2000-04-06  0:00     ` Robert Dewar

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