From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9573f92f22fc3481 X-Google-Attributes: gid103376,public From: "Nick Roberts" Subject: Re: File chicken counts eggs Date: 1997/05/08 Message-ID: <01bc5bfc$06b5df80$LocalHost@xhv46.dial.pipex.com>#1/1 X-Deja-AN: 240297006 References: <5kqku3$bch$1@netty.york.ac.uk> Organization: UUNet PIPEX server (post doesn't reflect views of UUNet PIPEX) Newsgroups: comp.lang.ada Date: 1997-05-08T00:00:00+00:00 List-Id: Mark Kambites 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.