lint question

Doug Gwyn gwyn at smoke.BRL.MIL
Tue Jan 10 12:33:15 AEST 1989


In article <491 at babbage.acc.virginia.edu> pts at watt.acc.Virginia.EDU (Paul T. Shannon) writes:
>function returns value which is always ignored
>    fprintf	    printf
>Is it bad style to use these functions without also checking the 
>returned value?

Since these functions can, and at times do, fail, in a robust program
you should indeed test their return values and take proper error-
recovery actions.  The one possible exception is
	(void)fprintf(stderr, "...: operation failed\n");
because if a write to the standard error output fails, you may have just
exhausted your error-recovery resources and can do no better anyway.
(What are you going to do, complain about THAT failure on stderr?)

Note the use of a (void) cast to explicitly discard an unused
function value.  This should not be done lightly; if properly used,
it indicates that the programmer realized that the function returns
a value but that it is not necessary in this particular instance to
use the value.  This will shut lint up, but that should not be the
prime motivation for using the cast!



More information about the Comp.lang.c mailing list