Pb mixing C & Fortran IO

craig@jcb-sc.com craig@jcb-sc.com
Sat May 8 07:21:00 GMT 1999


> I encounter a problem when mixing C and Fortran IO in my code. Here are samples that
> reproduce the problem :

Don't do that.  Any file or unit opened in one module cannot be safely
accessed in another module (via the usual language facilities, anyway,
which includes g77's libU77 routines, such as FGETC) *unless* that module
is uses the same level of language facilities (where Fortran's WRITE and
g77's FPUTC are on *two* different levels) *and* is compiled by the same
compiler.

And, yes, we need to document this.  We explain it this way in the docs
on each of the pertinent libU77 intrinsics:

  Stream I/O should not be mixed with normal record-oriented (formatted or
  unformatted) I/O on the same unit; the results are unpredictable.

However, we should explain it also in writeups on inter-language and
inter-compiler mixing.  I'll work on this later.

One approach I think some people use to avoid this whole problem is to
code all I/O in C, and all number-crunching in Fortran, when they have
to use both.

        tq vm, (burley)


More information about the Gcc-bugs mailing list