Re: Short records on unformatted reads
- From: nospam@xxxxxxxxxxxxx (Richard Maine)
- Date: Sun, 29 Oct 2006 12:52:02 -0800
Thomas Koenig <Thomas.Koenig@xxxxxxxxx> wrote:
What should the following program print?
program main
implicit none
integer, dimension(2) :: ia
open(10, form="unformatted", status="unknown")
write (10) 1, 'a'
rewind 10
ia = 42
read (10, err=20) ia
20 continue
print '(2I8)', ia
end program main
It is an illegal program, so the processor can do anything. You wrote an
integar and a character to the file. You then read two integers. That's
not legal (and is not likely to happen to work).
Note that the standard does not define I/O error conditions. It might
seem obvious to you (as it does to me) that this ought to count as an
error of teh kind that takes the err= branch, but the standard does not
require that. Most compilers probably will, but it isn't guaranted. I
once worked with a compiler that probably wouldn't for things like this.
Even if the err= exit is taken, the ia array becomes undefined in
standard speak. That's the whole array - not just the second element.
This means that it is illegal to subsequently reference it (until its
status changes).
If you reference it, the observed behavior may and probably does vary
among compilers. Thats' sort of the whole point of undefibnedness - to
avoid placing restrictions on compiler implementation in those cases.
Is the first number printed required to be 1?
No.
Is the processor free to print garbage as the second number?
Yes. Or to do anything else.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.
- Follow-Ups:
- Re: Short records on unformatted reads
- From: Thomas Koenig
- Re: Short records on unformatted reads
- References:
- Short records on unformatted reads
- From: Thomas Koenig
- Short records on unformatted reads
- Prev by Date: Re: Short records on unformatted reads
- Next by Date: Re: Online F77 information...
- Previous by thread: Re: Short records on unformatted reads
- Next by thread: Re: Short records on unformatted reads
- Index(es):
Relevant Pages
|
|