Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!apple!agate!shelby!rutgers!att!mcdchg!tellab5!mtcchi!levy From: levy@mtcchi.uucp (2656-Daniel R. Levy(0000000)0000) Newsgroups: comp.lang.c Subject: Re: Why use (void) func() ? Message-ID: <1990Oct4.031240.19394@mtcchi.uucp> Date: 4 Oct 90 03:12:40 GMT References: <586@dptechno.UUCP> <18307@haddock.ima.isc.com> Organization: Memorex Telex Corporation NSBG/STP Lines: 36 karl@haddock.ima.isc.com (Karl Heuer) writes: >In article ghoti+@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]