comp.lang.ada
 help / color / mirror / Atom feed
From: Charles Hixson <charleshixsn@earthlink.net>
Subject: Re: Circular type definition problem
Date: Mon, 11 Jun 2001 21:18:25 GMT
Date: 2001-06-11T21:18:25+00:00	[thread overview]
Message-ID: <BAaV6.4239$eZ6.598281@newsread2.prod.itd.earthlink.net> (raw)
In-Reply-To: yG9V6.9160$6d5.1914559@news2-win.server.ntlworld.com

But the purpose of the Count type declared in Direct_IO is to 
list record indicies, which is what I'm doing.  Unfortunately, as 
far as I can see, the type doesn't exist until I specialize it 
with:
package Node_IO is      new Ada.Direct_IO(Block);

But I want an index to the block (i.e., next_node) to be 
contained within the Block.

What I'm trying to avoid is defining an excessive number of 
types.  This is a type that is defined by the system to mean 
exactly what I want it to mean.  But I don't seem to be able to 
use it.

The reason that I tried the code that I did is because it is an 
exact parallel with Access allocation.  (And I don't think that I 
can refer to System.Direct_IO.Count'Last;, as I haven't yet got 
block defined.  

OTOH, if I can refer to System.Direct_IO.Count'Last; ,
then could I refer to the type System.Direct_IO.Count, and thus 
use my original code with only the addition of System.Dire... 
instead of Ada.Dire...

But then, again, would this mean that I would be needing to use 
Unchecked_Conversion when I wanted to refer to a particular 
record?  (This is one of the things that I wanted to avoid.)

Martin Dowie wrote:

> you could split out the implementation specifics into a seperate
> package e.g.
> 
> with System.Direct_IO;
> 
> package Project_Specifics is
> 
>    -- Specific to GNAT
>    --
>    Direct_IO_Count_Last : constant :=
>    System.Direct_IO.Count'Last;
> 
> end Project_Specifics;
> 
> 
> with Ada.Direct_Io;
> with Project_Specifics;
> 
> package Temp is
> 
>    type Byte is mod 256;
> 
>    type Block;
> 
>    type Blockdata is array (0 .. 511) of Byte;
> 
>    type Node_Count is range 0 ..
>    Project_Specifics.Direct_IO_Count_Last;
> 
>    type Block is
>       record
>          Next_Node : Node_Count;
>          Data      : Blockdata;
>       end record; -- Block
> 
>    pragma Pack(Blockdata);
>    pragma Pack(Block);
> 
>    package Node_Io is new Ada.Direct_Io(Block);
>    use Node_Io;
> 
> end Temp;
> 
> 
> "Charles Hixson" <charleshixsn@earthlink.net> wrote in message
> news:1s7V6.4021$Il5.510814@newsread1.prod.itd.earthlink.net...
>> This is what I'm trying to do:
>>         type Block;
>>         package Node_IO is      new Ada.Direct_IO(Block);
>>         use     Node_IO;
>>         type    BlockData       is      array (0..511) of Byte;
>>         type    Block   is      record
>>                 next_node       :       Node_IO.Count;
>>                 data                    :       BlockData;
>>         end record;     --      Block
>>         pragma pack(BlockData);
>>         pragma pack(Block);
>>
>> Not too much to my surprise, it didn't work.  Node_IO needs to
>> be
>> defined with a real type.  OTOH, the type Node_IO.Count is
>> defined within Node_IO, so I can't put it after the declaration
>> of Block.
>>
>> I suppose that I could just give up, and declare next_node to
>> be
>> Long_Integer, but that seems so inelegant.  Node_IO.Count is,
>> essentially, an Access variable (it says where in the file to
>> find the next Block).  But I'm not really sure how to approach
>> this.  Any suggestions?




      reply	other threads:[~2001-06-11 21:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-11 17:44 Circular type definition problem Charles Hixson
2001-06-11 20:16 ` Martin Dowie
2001-06-11 21:18   ` Charles Hixson [this message]
replies disabled

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