comp.lang.ada
 help / color / mirror / Atom feed
From: "Nick Roberts" <Nick.Roberts@dial.pipex.com>
Subject: Re: File chicken counts eggs
Date: 1997/05/08
Date: 1997-05-08T00:00:00+00:00	[thread overview]
Message-ID: <01bc5bfc$06b5df80$LocalHost@xhv46.dial.pipex.com> (raw)
In-Reply-To: 5kqku3$bch$1@netty.york.ac.uk




Mark Kambites <mek100@york.ac.uk> wrote in article
<5kqku3$bch$1@netty.york.ac.uk>...
> Hello fellow Ada users!
> 
> I'm attempting to implement a B-tree-type structure on disk. This
requires
> that each node in the tree contains file indices, indicating where in the
> file its children can be found. Such indices are implemented in Ada as
the
> 'count' type which is declared in direct_io. Unfortunately, nothing in
> direct_io is visible until direct_io has been instantiated, and I need
> to instantiate it with my node as the generic type parameter. Have you
> spotted the problem yet?
> 
> It seems that the size of my node must be known to the compiler before
> direct_io can be instantiated, and the size of the node is dependant upon
> the size of 'count', which is unknown UNTIL direct_io HAS BEEN
instantiated.


I think it is generally acknowledged that the COUNT type declared in
SEQUENTIAL_IO, DIRECT_IO, and TEXT_IO (in Ada 83) was a mistake. A
predefined integer type should have been used instead; among other things,
this would have obviated the problem you encounter.

Since you are (presumably) using multiple instantiations of DIRECT_IO, each
instantiation will give rise to a (nominally) different type COUNT. Thus,
you cannot avoid explicit type conversions.

Technically, given instantiations such as:

package FILE_1_IO is new DIRECT_IO(TYPE_1);
package FILE_2_IO is new DIRECT_IO(TYPE_2);
package FILE_3_IO is new DIRECT_IO(TYPE_3);

you should declare a new type:

type OVERALL_COUNT is range 0 .. MAX(MAX(FILE_1_IO.COUNT'LAST,
FILE_2_IO.COUNT'LAST), FILE_3_IO.COUNT'LAST);

where MIN and MAX are declared as appropriate.

However, this is so clumsy, you may want to simply declare OVERALL_COUNT as
0 .. SYSTEM.MAX_INT, or some other big range which works.

Either way, you will have to declare components of type OVERALL_COUNT in
your tree, and convert explicitly as required.

Nick.






  reply	other threads:[~1997-05-08  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-05-07  0:00 File chicken counts eggs Mark Kambites
1997-05-08  0:00 ` Nick Roberts [this message]
1997-05-08  0:00 ` Robert I. Eachus
replies disabled

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