This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: redirection in gfortran and g95


> The current g95 and gfortran compilers do not keep the i/o
> synchronized. My test case shows that when you redirect the
> output from a g95 or gfortran built binary that prints a
> from the fortran subroutine before and after a c++ subroutine
> prints that the resulting fortran output isn't in the proper
> locations. Rather than it occurs either in the middle of the
> c++ i/o or after it.
>      Andy Vaught believes that this is indeterminate behavior

He is right in saying so. In mixed language code, it is the job of
every bit of code to keep the I/O synchronized, that is, to flush the
I/O streams it uses after it has written in it.

gfortran does flush the streams it uses, but the C++ part of your
example program does not. Indeed, many compilers works around this
problem by preventively flushing the standard output, and that could
be considered for gfortran, but:

 1. it only fixes the case of stdout/stderr, since we can flush all
open files just in case

  2. it's a hack to work around bad programming pratices, which I'm
not sure we want to do.

So, I think the best solution is to get the original code fixed, but
addind a few calls to flush the stdout when C++ has used it and before
the fortran code is called. This is a personnal opinion, of course,
and some other people around should say what they think is better.

FX

PS: there is a PR opened for that in bugzilla (assigned to me,
actually), but i can't look at its number now.


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