tech-misc archive

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

Re: __attribute__((warn_unused_result)) for NetBSD?



>> The question is whether something like
>>      printf("done\n");
>> is "perfectly good code", [...]
> I also don't see reasons to checks return value printf.

>>> write, read, fwrite, fread...?
>> None of those qualify, IMO, though read and fread come close.
> Why?  IMO Not checking for return value of all these functions as
> well as close fclose etc. is VERY dangerous.

Why do you think it's OK to ignore error checks on printf but not on
write?  I'm having trouble seeing the relevant difference.

Also see below.

>> 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.
> I didn't suggest to ALWAYS produce such warnings.

No, but the granularity of producing them is the compilation unit;
there is no way to control it per-called-function without hacking up
the include files.

That is, if I call (say) write() in a circumstance where I don't
consider it necessary to check the return value, I have only a few
options:

1) Turn off unused-result warnings entirely, at least for that file.

2) Hack up the include file to remove the marking from write().

3) Don't use -Werror, and ignore the warning message.

4) Uglify the code with a (void) cast.

I won't do (4) - I have major philosophical disagreement with the idea
that it's somehow inherently dangerous and thus deserves special markup
to ignore a returned value - and will do (3) only for occasional use on
systems I don't run.  Whether I'd do (1) or (2) would probably depend
on experiment: I'd use (2) for a while and see whether the warnings
held enough value to be worth maintaining the include-file hacks.

/~\ 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