Possibly correct approach to warn_unused_result

Jan Dvořák mordae at thirdcms.org
Tue Mar 27 09:30:59 PDT 2007


Hi,

	there is an header file in the attachment -- ignore.h -- that defines 
three macros; ignore(), ignorep() and ignoreb(). These can be used to 
suppress warn_unused_result warnings safely without any direct 
consequences to the application itself.

	Unlike assert(), ignore() displays warning for negative results (as 
most of the C library functions returns -1 on error), ignorep() (ignore 
pointer) for zero result (it actually casts it to (int) from pointer it 
should receive) and ignoreb() (ignore boolean) prints warning for false 
(0) expressions and none of these terminates application.

	About fread/fwrite checks; C library does not set errno != 0 for cases 
when fread/fwrite reads/writes short item count. So I don't think it is 
necessary to check for these cases (they are pretty rare anyway).

	What do you think about using this header for HLFS build?

	Note that even unlike their names suggests, these macros don't actually 
bury the return value. They use gcc extension -- compbound command in 
brackets -- to return original expression result (last command 
expression of block), so they can be used even as sanity checks. I mean 
`res = ignore(fread(...))` assigns `res` correct value.

- Mordae
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ignore.h
URL: <http://lists.linuxfromscratch.org/pipermail/hlfs-dev/attachments/20070327/b1864fca/attachment.h>


More information about the hlfs-dev mailing list