Why use (void) func() ?

2656-Daniel R. Levy00000000000 levy at mtcchi.uucp
Thu Oct 4 13:12:40 AEST 1990


karl at haddock.ima.isc.com (Karl Heuer) writes:

>In article <oazbx9O00VtqAheFBf at andrew.cmu.edu> ghoti+ at andrew.cmu.edu (Adam Stoller) writes:
>>I happen to agree that having printf() return an int is rather a waste,
>>but if/when it bothers me, I either go through the code and put the void
>>cast in front of each printf, or [fake it with a macro].

>My opinion: the disease is pretty mild, but so are the symptoms (a single
>entry in one line of lint output); and I'd rather keep the latter around in
>case I someday decide to repair the former.  I actually have one program that
>lints cleanly, modulo lint bugs, and does not do any such fudging: output is
>done with
>	void pprintf(Player *p, char const *fmt, ...) {
>	    va_list ap;
>	    va_start(ap, fmt);
>	    if (vfprintf(p->ofp, fmt, ap) < 0) bugcheck();
>	    va_end(ap);
>	    if (fflush(p->ofp) == EOF) bugcheck();
>	}

Hmm.  This idea could be carried a step further by providing a means of
specifying a particular error handler at different points in the flow of the
code.  Maybe you don't always want to quit with a bug check at a critical
portion of the code, instead you'd rather try your best to clean up before
exiting or even ignore the write error if it doesn't affect the ultimate result
of the program.  (But then why did I try to write, you say?  Well, the failed
writes might be status messages for human viewing, which normally go to the tty
but which someone redirected into a file on a filesystem which has now filled
up.  If you're in the middle of a critical data file manipulation when that
happens, you likely don't want to just -- **boom** -- quit with files in a
confused state.)
-- 
 Daniel R. Levy * uunet!tellab5!mtcchi!levy * These views not on behalf of MTC
so far as I can remember, there is not one    | ... THEREFORE BE AS SHREWD AS
word in the gospels in praise of intelligence.| SERPENTS [SEE GEN. 3] AND HARM-
-- bertrand russell [berkeley unix fortune]   | LESS AS DOVES -- JC [MT. 10:16]



More information about the Comp.lang.c mailing list