comp.lang.ada
 help / color / mirror / Atom feed
* Stream_IO
@ 1998-03-04  0:00 Tom Moran
  1998-03-04  0:00 ` Stream_IO John J. Cupak Jr.
  1998-03-04  0:00 ` Stream_IO Stephen Leake
  0 siblings, 2 replies; 3+ messages in thread
From: Tom Moran @ 1998-03-04  0:00 UTC (permalink / raw)



Is there a way to use Stream_IO to read a file produced by other than
the program doing the reading, in particular, a file binary file
produced, say, with C?  The RM indicates the representation is
implementation defined, and 'read apparently quite ignores rep
clauses, so I find one compiler reads integer things of 'size 8 or 16
as 16, and another reads size 16 things as size 32.  I hate to read
into a String and then do Unchecked_Conversions or 'address overlays,
but I don't see any other portable approach.  Help!




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

* Re: Stream_IO
  1998-03-04  0:00 Stream_IO Tom Moran
  1998-03-04  0:00 ` Stream_IO John J. Cupak Jr.
@ 1998-03-04  0:00 ` Stephen Leake
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Leake @ 1998-03-04  0:00 UTC (permalink / raw)



Tom Moran wrote:
> 
> Is there a way to use Stream_IO to read a file produced by other than
> the program doing the reading, in particular, a file binary file
> produced, say, with C?  The RM indicates the representation is
> implementation defined, and 'read apparently quite ignores rep
> clauses, so I find one compiler reads integer things of 'size 8 or 16
> as 16, and another reads size 16 things as size 32.  I hate to read
> into a String and then do Unchecked_Conversions or 'address overlays,
> but I don't see any other portable approach.  Help!

I went around on this with Tucker Taft last fall, and the answer is: in
general, you have to do unchecked conversion, and you have to live with
the compiler differences.

To make this (slightly) easier to swallow, consider trying to read a 12
bit integer from a stream. Since streams are defined in terms of memory
words, if you are using an 8 or 16 bit word architecture, you will have
to do some conversion to get 12 bits.

The fact that some compilers read more than 8 bits for 8 bit integers
from 8 bit streams is a consequence of the rules about base integer
types; if the compiler chooses a 32 bit integer base type for an 8 bit
integer type, it MUST read and write 32 bits from/to streams. This is an
area that would benefit from uniformity guidelines, but it is not a
simple issue, since it trades stream uniformity for arithmetic
efficiency.

-- 
- Stephe




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

* Re: Stream_IO
  1998-03-04  0:00 Stream_IO Tom Moran
@ 1998-03-04  0:00 ` John J. Cupak Jr.
  1998-03-04  0:00 ` Stream_IO Stephen Leake
  1 sibling, 0 replies; 3+ messages in thread
From: John J. Cupak Jr. @ 1998-03-04  0:00 UTC (permalink / raw)
  To: Tom Moran


Tom Moran wrote:
> 
> Is there a way to use Stream_IO to read a file produced by other than
> the program doing the reading, in particular, a file binary file
> produced, say, with C?  The RM indicates the representation is
> implementation defined, and 'read apparently quite ignores rep
> clauses, so I find one compiler reads integer things of 'size 8 or 16
> as 16, and another reads size 16 things as size 32.  I hate to read
> into a String and then do Unchecked_Conversions or 'address overlays,
> but I don't see any other portable approach.  Help!

Tom,

I solved a similar problem a while ago by creating a "Byte_IO" package,
with generic Read and Write procedures for the user's data (typically, a
record).

The package instantiated Sequential_IO for bytes, and did unchecked
conversion of the user's data (in the generic Read and Write code
bodies) to byte arrays of corresponding size which were then read and
written (depending on the appropriate procedure, of course).

The application program had to "know" what kind of data it was supposed
to read or write, as the generic Read and Write procedures certianly did
not. This was easy, actually, since the first read/write was always a
"header" record containing the counts of the various data records.

Hope this helps. 
-- 
--------------------------------------------------------------
-                 John J. Cupak Jr, CCP                      -
- Raytheon Systems Company - Software Engineering Laboratory -
- tel: 508-858-1222   email (work): jcj@swl.msd.ray.com      -
- fax: 508-858-4336   email (home): jcupak@aol.com           -
--------------------------------------------------------------




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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-03-04  0:00 Stream_IO Tom Moran
1998-03-04  0:00 ` Stream_IO John J. Cupak Jr.
1998-03-04  0:00 ` Stream_IO Stephen Leake

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