Discarded Function Values (To Cast or Not to Cast)

Doug Gwyn gwyn at smoke.BRL.MIL
Sat Nov 18 02:47:27 AEST 1989


In article <316 at voa3.UUCP> ck at voa3.UUCP (Chris Kern) writes:
>But what about a standard library function whose value I
>(perhaps recklessly) wish to ignore?  Should I cast the function
>call to void, or am I just indulging in the trivial luxury of
>silencing lint?

C does not require the (void) cast of the unused return value.
As a matter of policy, you shouldn't do things JUST to "shut lint up".
Lint is warning you that functions return success status etc. by
design and that it may be unwise to fail to check the returned status.
Therefore, I would say that for each such warning you should THINK
whether or not the returned value is important for the context in
which the function is invoked, and if so do something about it, or
if not then explicitly discard the value with a (void) cast.  If you
follow that policy, then the reader of your code will KNOW that (void)
means that you've thought about it and decided the return value was
not needed.  Without the explicit (void) he would have no way to tell
if there had been an oversight.



More information about the Comp.lang.c mailing list