Re: Short records on unformatted reads



Richard Maine <nospam@xxxxxxxxxxxxx> wrote:

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).

Thanks!

Note that the standard does not define I/O error conditions.

Yes, I had forgotten to take that into account...

Even if the err= exit is taken, the ia array becomes undefined in
standard speak.

If I replace the line
read (10, err=20) ia
with
read (10, err=20) ia(1), ia(2)
or
read (10, err=20) (ia(i),i=1,2)

(and add integer::i as appropriate above)

then I would expect ia(1) to be defined, though.
.