Flushing libgfortran from C
N.M. Maclaren
nmm1@cam.ac.uk
Thu Mar 3 10:27:00 GMT 2011
On Mar 3 2011, Tobias Burnus wrote:
>
>For flushing the buffer, you could simply call from C:
> _gfortran_flush_i4 (NULL);
>
>It should solve at least some of your problems. However, I do not
>understand why you get an empty stdout. To my knowledge, stdout is not
>buffered. (Unless that's different in 4.4.)
Er, no. That's stderr you are thinking of. Also, even stderr is buffered
on many non-Unix systems - and damn what the C standard says, because it's
unimplementable!
I must say that I am surprised that stderr is unbuffered rather than line
buffered in gcc, even under Linux, but that's another matter.
>(I admit that having a call which properly shuts down the library would
>be sometimes useful.)
I would say "badly needed".
On this matter, my suspicion is that the Rice people have got it wrong.
I can't think of any good reason to call _exit in that case. To give
them some slack, here is a description of the C standard situation:
C90 had the exit function, which calls atexit and flushes C's buffers;
C99 added the _Exit function, which does not call atexit functions or
honour signal handlers and it is implementation-defined whether it
flushes C's buffers; this was copied from the _exit function, which was
introduced by POSIX; C1X is adding the quick_exit function, which does
not call atexit functions but does call at_quick_exit ones, does not
honour signal handlers, and it is UNDEFINED whether it flushes C's
buffers. It is undefined behaviour to call exit from quick_exit or
vice versa, but apparently not to call _Exit from either or indeed
conversely! God alone knows what implementors will do with that mess.
Regards,
Nick Maclaren.
More information about the Fortran
mailing list