comp.lang.ada
 help / color / mirror / Atom feed
From: bobduff@dsd.camb.inmet.com (Bob Duff)
Subject: Re: Portable way to read/write from a binary file?
Date: Mon, 19 Sep 1994 17:46:15 GMT
Date: 1994-09-19T17:46:15+00:00	[thread overview]
Message-ID: <CwE1D4.yH@inmet.camb.inmet.com> (raw)
In-Reply-To: 35iuqj$5dj@goanna.cs.rmit.oz.au

In article <35iuqj$5dj@goanna.cs.rmit.oz.au>,
Dale Stanbrough  <dale@goanna.cs.rmit.edu.au> wrote:
>In article <Cw717J.66q@alsys.com> , kst@alsys.com writes:
>>For Ada 94 (assuming X=4 8-)}), I think Stream_IO does what you want.
>>
>
>Unfortunately not (as I read it!)
>Each object in a stream has a tag appended to it so that the 
>procedure S'Class'Read can reconstruct the value from the tag 
>contained within the stream (13.13.2.14).

No.  S'Class'Read and S'Class'Write do not generally read and write tags.
(S'Class'Input and S'Class'Output do.)
Furthermore, if you're not using tagged types, then no tags are written
or read by any of these things.

The Stream_IO package and the streams stuff in 13.13 are definitely
intended for doing binary I/O.  A typical case is where the various
types are *not* tagged (or discriminated or unconstrained arrays or
anything fancy like that), and S'Write and S'Read can be used directly.
You won't get tags or other dope mixed in with your data.

>As well the representation of stream elements is implementation
>defined (13.13.2.17)

True, but in practice that's not a big problem.  After all, the
representation of Sequential_IO, Direct_IO, and Text_IO files are also
implementation defined.  You have to trust the implementation to use a
"reasonable" representation.  13.13.2(18-20) give advice about what a
reasonable representation is.  Most languages that support binary I/O
are similar in this regard.  (Not COBOL, though.)

>The best solution seems to be to use pragma import or use the
>Posix_IO package.

Note that Posix_IO, or pretty much any other I/O package, also has an
implementation-defined representation of the data.
-- 
Bob Duff                                bobduff@inmet.com
Oak Tree Software, Inc.
Ada 9X Mapping/Revision Team (Intermetrics, Inc.)



  reply	other threads:[~1994-09-19 17:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-09-14  1:40 Portable way to read/write from a binary file? Dale Stanbrough
1994-09-14  3:51 ` Robert Dewar
1994-09-16  1:47   ` Lee_Robert_Willis
1994-09-14 22:39 ` Dale Stanbrough
1994-09-15 17:08   ` Robert Dewar
1994-09-16  5:00   ` R_Tim_Coslet
1994-09-19  2:59     ` Dale Stanbrough
1994-09-19 17:46       ` Bob Duff [this message]
1994-09-20 22:51       ` Dale Stanbrough
1994-09-15 22:59 ` Keith Thompson @pulsar
replies disabled

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