This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: redirection in gfortran and g95
- From: François-Xavier Coudert <fxcoudert at gmail dot com>
- To: Jack Howarth <howarth at bromo dot msbb dot uc dot edu>
- Cc: fortran at sources dot redhat dot com
- Date: Fri, 22 Jul 2005 22:42:45 +0200
- Subject: Re: redirection in gfortran and g95
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=CMaEWdRPouSCWEdIgQEFxOuiDDwZfiQfHQBBudF7IfxJIcwX9426XSw5BTGKjO8EhDFFQ+FcVFwuFq2yRYSSS9m3k0GdfGzrRsn0Z/jhhhXSGLPpui3eYouMO+9zANTMOnGg9paNOfmK+Hqx6je+6cNcSMPVMLKNJIk9qgb61+g=
- References: <20050721150933.56F7E1DC0BB@bromo.msbb.uc.edu>
- Reply-to: François-Xavier Coudert <fxcoudert at gmail dot com>
> 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.