This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: FreeBSD Fortran Failure


Mark Mitchell wrote:

> >>>>> "Toon" == Toon Moene <moene@knmi.nl> writes:
> 
>     Toon> I'll cook up a patch tonight for you to test.

> If that doesn't fix it, I'll try to step through all of this stuff
> really, really carefully with a GNU/Linux box in one window and the
> FreeBSD box on the other, and see if I can figure out what the heck is
> going on.

Unfortunately, the following causes the testsuite case to fail on Debian
2.2 - perhaps I'm overlooking something obvious:

toon@laptop:~/compilers/releases/gcc/libf2c/libI77$ diff -rcp2N
endfile.c.orig endfile.c
*** endfile.c.orig      Wed Feb 28 01:42:29 2001
--- endfile.c   Mon May 14 19:04:29 2001
*************** done:
*** 131,134 ****
--- 131,136 ----
        fflush(b->ufd);
        rc = ftruncate(fileno(b->ufd),loc);
+       if (!(bf = freopen(b->ufnm, f__w_mode[0], bf)))
+               rc = 1;
  #endif /* !defined(HAVE_FTRUNCATE) */
        if (rc)

(Sorry, I don't have time before Wednesday to seriously look into this,
so unless someone has a bright idea - hint, hint - it will have to wait
for two days).

> I don't read Fortran very well.  Can you explain what the contents of
> the file should be at each of the various lines?

Well, the code is obvious :-) [ it must be - it doesn't have comments ]

*     Fixed by 1998-09-28 libI77/open.c change.
      open(90,status='scratch')
      write(90, '(1X, I1 / 1X, I1)') 1, 2
      rewind 90
      write(90, '(1X, I1)') 1
      rewind 90                 ! implicit ENDFILE expected
      read(90, *) i
      read(90, *, end=10) j
      call abort()
 10   end

The first line is a comment (oops, am I contradicting myself or what :-)
Line two opens a scratch file for (formatted, i.e. text) reading and
writing on unit 90.
The third line writes two "lines" (records, to be precise) to the file
indicated by unit 90.  The first line in that file will contain a space
followed by a "1", the second line will contain a space followed by a
"2".
The fourth line rewinds the file (this means that any subsequent write
will start at the beginning of the file). It also performs an implicit
ENDFILE statement that truncates the file (which involves no action at
this point).
The fifth line writes a single "line" (one record) to the file indicated
by unit 90, consisting of a space followed by a "1".
The 6th line rewinds the file for the second time.  Now the implicit
ENDFILE statement *really* truncates the file, so that the second line
is removed.
The 7th line reads the first "line" (record) from the file indicated by
unit 90 and converts the space, "1" to the value 1 for INTEGER i.
The 8th line attempts to read the second "line" (record) from file "90"
but fails because of the implicit truncation caused by the REWIND of
line 6.  This end-of-file failure results in control passing to the line
with label 10, which ends the program, skipping the call to ABORT.

Note: All "lines" (records) in file "90" end with an (implicit) newline.

You see, Fortran is soooo simple, you could learn it the way I did 22
years ago (namely by looking at code others had written - who learned
Fortran by looking at code .... well, you get the jist :-)

Try *that* with C++ :-)

-- 
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands
Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
Join GNU Fortran 95: http://g95.sourceforge.net/ (under construction)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]