tech-misc archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: __attribute__((warn_unused_result)) for NetBSD?



> Ok. I see at least two different approaches to this.
> 1) provide checks for result values of functions may fail (my logic)
> 2) provide checks for function with no side effects

> Which is better?  This depends on your/my religion :-)

Right.

Warnings that are too verbose on perfectly good code are actually of
negative value, because they conceal "real" warnings.  The question is
whether something like

        printf("done\n");

is "perfectly good code", or whether it needs to be cast to void to
qualify.

This is why I stopped using lint; it produces content-free warnings
like "pointer casts may be troublesome", to the point where I found the
time lost sorting through its output looking for anything worth reading
was more than the time lost to the bugs I had to find the hard way.
(gcc helps this substantially because it has warning options that
provide many of the more valuable checks lint did, without the drivel.
There was a time when I had a lint postprocessor which tried to clean
up the useless noise; even with that I found it of negative value.)

Of course, the compiler is free to warn about anything it feels like
("warning: your indentation style is inconsistent", "warning: your
variable names are confusingly similar").  But one which produces too
many warnings about non-problems will provoke the above effect, hiding
warnings about real problems amid useless noise.

>> What I do _not_ consider reasonable is using it for functions with
>> useful side effects, such as printf.
> Ok. Do you see 100% candidates for "protection" from the list I sent?

That depends on whether you mean "are there any functions which 100%
deserve the marking?" (which I answer "yes") or "is the list 100%
functions which deserve the marking?" ("no").

The functions which I think deserve the marking are functions with no
side effects (abs, atof, atoi, atol, feof, etc) and a few functions
which, while they have side effects, have side effects that I cannot
see any use for without the return value (fopen, malloc, etc).

> write, read, fwrite, fread...?

None of those qualify, IMO, though read and fread come close.

Don't mistake me.  I think that routinely checking the return values of
functions like write() and chdir() is good.  I just think demanding
_always_ checking them is going too far.

/~\ The ASCII                           der Mouse
\ / Ribbon Campaign
 X  Against HTML                mouse%rodents-montreal.org@localhost
/ \ Email!           7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B


Home | Main Index | Thread Index | Old Index