🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: src.ada
Article #1

Re: sequential io with multiple types

#1
From: John Goodenough
Date: Tue, 27 Oct 1992 15:21
32 lines
2178 bytes
In article <9210160237.AA26805@akela.src.honeywell.com>,
englehar@src.honeywell.com (Matt Englehart) writes: 

|> Along the same lines as my previous question, suppose that I have a file
|> with short_floats and integers written out in binary format (by a fortran
|> program, as real*4 and integer*4).  If I instantiate SEQUENTIA_IO with type 
|> integer, and read all data as an integer, how do I convert data that is not
|> an integer from the integer value read in to the true short_float
|> representation?

The obvious answer here is to use unchecked conversion.  This is a good
example of well-justified use.

A less obvious answer is to point out that Ada allows a program to open the
same external file with *different* data types, i.e., you can instantiate
SEQUENTIAL_IO with different data types, declare a file object for each of the
instantiated file types, and apply the appropriate open procedure to each of
these file objects using the same external file name.  Then you read from an
appropriate file object depending on what type of data you expect the next
file element to be.

This is allowed because the Ada OPEN procedure is not the same as the
operating system notion of opening a file -- OPEN in Ada only establishes an
"association" between an (internal) file object and an external file.

Of course, not all Ada implementations support such multiple "openings" of the
same external file because this behavior is not required by the standard, but
it is allowed, and it is quite useful if an implementation supports it.

John B. Goodenough					Goodenough@sei.cmu.edu
Software Engineering Institute				412-268-6391
Technical Details
Message-ID: <1992Oct27.152146.17600@sei.cmu.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!usc!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!news.sei.cmu.edu!jbg
References: <9210160237.AA26805@akela.src.honeywell.com>

Show Full Headers
Complete Article Headers
Newsgroups: src.ada,comp.lang.ada
Path: arc1-ca.pugleaf.net!sparky!uunet!usc!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!news.sei.cmu.edu!jbg
From: jbg@sei.cmu.edu (John Goodenough)
Subject: Re: sequential io with multiple types
Message-ID: <1992Oct27.152146.17600@sei.cmu.edu>
Sender: netnews@sei.cmu.edu (Netnews)
Organization: The Software Engineering Institute
References:  <9210160237.AA26805@akela.src.honeywell.com>
Date: Tue, 27 Oct 1992 15:21:46 GMT
Lines: 32