Subject: Re: ignoring return values from functions.
To: None <tech-userlevel@netbsd.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-userlevel
Date: 09/29/2001 20:50:15
>> Casting return values to (void) is even explicitly discouraged by
>> several style guides [...]

> I would consider such style guides VERY misguided.

And I wouldn't.  So?

> Lint in particular is very correct in complaining about such errors
> and it's advice should be taken if at all possible!

> It is ALWAYS best to explicitly cast function return values to (void)
> if they are expliicltly to be ignored.

I can't help wondering what's up with you that you feel compelled to
present your opinions - for that's really all these are - as if they
were facts.

I can't think of *any* style rule that is "ALWAYS" better followed than
ignored - with the possible (Hofstadterian :-) exception of this one: I
think that every other style rule I've seen, I've seen exceptions to.

> We're not talking about the basic correctness of the code here, but
> rather the readability and future maintainability of the code.

Perhaps.  But that really depends on the future reader and maintainer.
Personally, I find (void) all over the place says "this code author
thinks shutting up automated checking tools is more important than
clearly expressing the desired algorithm".  Anyone who relies more on
software than wetware for style checking (as opposed to correctness
checking) I distrust, just as I do authors who rely on spellchecker
software to spell properly.  And just as the latter tends to be
evidenced by text with homophonic mistakes, all correctly spelled (the
"and it's advice" I quoted above is a possible example), code full of
(void) casts serving no purpose but muffling lint's complaints
evidences the former to me.

> If all callers to a function ignore its return value then it should
> be declared 'void' in the first place.

Unless it is as it is for the sake of conforming to an interface
(whether for correctness or stylistic reasons).

> [I]t's probably best in the specific case of NetBSD to simply make a
> distinction in the style guide between printf() and fprintf() and any
> other non-void functions.

Why single out printf and fprintf?  Are you under the illusion that
those are the only calls whose return values may reasonably be ignored
all, or almost all, of the time?

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