stderr vs. STDERR_FILENO
Jonathan Lennox
lennox@cs.columbia.edu
Wed Feb 25 17:30:00 GMT 2004
Zack Weinberg <zack at codesourcery dot com> writes:
> For what it's worth I think this is primarily a documentation issue -
It just occured to me -- no, unfortunately, this is a correctness issue.
This C++ program is well-defined by the standard -- it invokes
std::terminate, which invokes abort().
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: except.cpp
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20040225/5fd5dfa4/attachment.ksh>
-------------- next part --------------
However, given a general-purpose C library which complies only with the
requirements of the C/C++ standards, __gnu_cxx::__verbose_terminate_handler
invokes undefined behavior on this program.
Now, as a matter of QoI, I suspect that in almost every actual C library a
write to a closed stderr will always fail with EOF, which means that my
little program still has the behavior mandated by the standard.
I suggest that, in addition to Zack's warning documentation, there be a
target-specific configuration flag for libstdc++ which specifies that the
underlying C library doesn't support writes to stderr after fclose. In
those cases, std::terminate should just be abort().
--
Jonathan Lennox
lennox at cs dot columbia dot edu
More information about the Gcc-patches
mailing list