Subject: Re: ignoring return values from functions.
To: NetBSD Userlevel Technical Discussion List <tech-userlevel@NetBSD.ORG>
From: Greg A. Woods <woods@weird.com>
List: tech-userlevel
Date: 09/19/2001 18:13:23
[ On Wednesday, September 19, 2001 at 04:12:20 (+0200), Matthias Buelow wrote: ]
> Subject: Re: ignoring return values from functions. 
>
> Casting return values to (void) is even explicitly discouraged by
> several style guides and probably stems from the use of some checking
> tools (some versions of lint perhaps?) and compilers which were a bit
> overzealous with things...

I would consider such style guides VERY misguided.  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.  We're not talking about the basic
correctness of the code here, but rather the readability and future
maintainability of the code.

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

Of course this raises some ugly problems for functions defined by the C
Standard, but whose return values are rarely examined (or which are
available by other means).  Lots of poor hacks can be applied, but it'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.

> I would propose sticking to the style as published in the Kernighan&
> Ritchie authored books (or Kernighan&Pike, 1999), although this is
> then again somewhat different from NetBSD's style again, but only
> in details.

K&R's style isn't entirely best for production use -- it is purposefully
simplified to make learning the language easier.  Yes, it should be
followed in its general intent, but stuff like casts to 'void' where
return values are intended to be ignored are well known and widely
followed enhancements to the "original" K&R style.

-- 
							Greg A. Woods

+1 416 218-0098      VE3TCP      <gwoods@acm.org>     <woods@robohack.ca>
Planix, Inc. <woods@planix.com>;   Secrets of the Weird <woods@weird.com>