Comment 6 for bug 305176

Revision history for this message
In , Joseph-codesourcery (joseph-codesourcery) wrote :

Subject: Re: can't voidify __attribute__((warn_unused_result))

On Wed, 21 Dec 2005, pinskia at gcc dot gnu dot org wrote:

> The reason why it is a glibc bug is that it is very over the top of adding the
> attribute here.

And indeed there is no logical difference between printf and fwrite here,
but glibc is marking fwrite and not printf.

In both cases, a valid programming style is to use fflush and ferror at
the end to check for errors, rather than checking on every write, or to
check the return value of fclose. A program that uses fwrite without
checking the return value or such a subsequent error is buggy - so is one
using printf and failing later to check for errors on stdout. (GCC is
among such buggy programs; "gcc --help >/dev/full" does not return error
status as it should.) But checking at the end suffices (albeit losing
information about the value of errno for the original error), you don't
need to check at every call.