Re: Detect EOF for direct access, unformatted files?



On Sun, 24 Apr 2005 11:21:54 +0100, Clive Page wrote:
> I have used code exercising this feature on at least a dozen
> compilers on almost as many platforms over many years, and have
> *never* encountered a system which returns zero for a record beyond
> the "end" of the direct-access file.


$ gfc -v
Using built-in specs.
Target: i386-linux
Configured with: ../gcc/configure --prefix=/tmp/gfortran-20050423/irun --enable-languages=c,f95 --host=i386-linux
Thread model: posix
gcc version 4.1.0 20050423 (experimental)

$ gfc filesize.f

$ ./a.out

i: 1 myiostat: 0
i: 2 myiostat: 0
i: 3 myiostat: 0
i: 4 myiostat: 0
i: 5 myiostat: 0
i: 6 myiostat: 0
i: 7 myiostat: 0
i: 8 myiostat: 0
i: 9 myiostat: 0
i: 10 myiostat: 0
i: 11 myiostat: 0
Bus error (core dumped)


$ cat filesize.f
implicit none

integer i,j
integer myarray(100)
integer myiostat

do i=1,100
myarray(i) = i
end do

open(unit=10,file='filesize.out', access='direct',
& status='replace', recl=400)
do i=1,10
write(unit=10,rec=i) (myarray(j), j=1,100)
end do
close(unit=10)

open(unit=20, file='filesize.out', access='direct',
& status='old', recl=400)
do i=1,20
read(unit=20, rec=i,err=100, iostat=myiostat)
& (myarray(j), j=1,100)
print *, 'i: ', i, ' myiostat: ', myiostat
end do
close(unit=20)

! spaghetti jump to end if no error
go to 300

! else handle error here
100 print *, 'error encountered'
print *, 'i: ', i, ' myiostat: ', myiostat

300 continue
end


.



Relevant Pages

  • Re: Am I right here?
    ... >> Modern compilers IMO are going to do pretty much the same thing in all ... >initialization code will zero-out each variable in the table ... Some platforms have instructions that can set ... >not have each byte assigned to zero. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: "Default construction" of built-in types?
    ... Comment could have been extended to say "on other compilers, platforms, etc.." ... given that I didn't know if the initialization to zero was standard. ...
    (comp.lang.cpp)