tech-misc archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: __attribute__((warn_unused_result)) for NetBSD?
On Tue, Sep 16, 2008 at 12:56:01AM +0300, Aleksey Cheusov wrote:
> I already made my desicion years ago - in programming paranoia is good.
There's necessarily a tradeoff between paranoia and pragmatism.
Finding the right balance is essential.
> The original question was... Do you like an idea of marking functions
> (conditionally! e.g. if WARNS=4 etc.) with "warn_unused_result" IN
> GENERAL? And if yes, _what kind of functions_ you WILL mark with it.
Yes, but cautiously.
> Variants:
> 1) this mark is useless at all
> 2) only for functions with no side effects
> 3) for some functions that may fail (read, write etc.)
> 4) 2 + 3
Setting warn-unused-result on that may fail is nearly useless. You
want warn-missing-failure-check, which is a lot harder to implement.
Warn-unused-result is not an adequate substitute; consider these code
fragments:
(1)
int *x = malloc(sizeof(*x));
*x = 3;
(2)
int result = read(fd, buf, maxlen-1);
buf[result] = 0;
--
David A. Holland
dholland%netbsd.org@localhost
Home |
Main Index |
Thread Index |
Old Index