Unbuffered output in mixed C / Fortran programs

Georg Denk news_gd@gmx.de
Wed Oct 15 15:21:00 GMT 2008


Hello Tobias!

Tobias Burnus wrote:
> Try FLUSH. The following uses a Fortran 2003 feature:
> 
>       SUBROUTINE FORTRAN_OUTPUT
>       USE ISO_FORTRAN_ENV   !!! make OUTPUT_UNIT available
>       WRITE(*,*) 'HELLO WORLD, FORTRAN (should be 1st)'
>       FLUSH(OUTPUT_UNIT)  !!! FLUSH standard out (stdout)
>       RETURN
>       END
> 
> Besides OUTPUT_UNIT, you can use INPUT_UNIT and ERROR_UNIT or any
> numerical unit such as "FLUSH(99)".
> 
> In C one can use, e.g.,  fflush(FILE *stream) to do the same there; e.g.
> "fflush(stdout);"

Thanks for this hint. To be honest, I was aware of flush, and it might be
a solution for this simple test case. But for the real thing, there are so
many output statements that it is more or less impossible to add
some flush to all of them. That's the reason for the setvbuf call in
the C part which is similar to adding a "flush" after each printf.

The behavior seems to be gfortran specific, as I don't see it
with other compilers. It also worked with GCC 3.4.x.

Best wishes,

Georg

-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger



More information about the Fortran mailing list