Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!know!zaphod.mps.ohio-state.edu!julius.cs.uiuc.edu!psuvax1!rutgers!rochester!pt.cs.cmu.edu!o.gp.cs.cmu.edu!andrew.cmu.edu!ghoti+ From: ghoti+@andrew.cmu.edu (Adam Stoller) Newsgroups: comp.lang.c Subject: Re: Why use (void) func() ? Message-ID: Date: 24 Sep 90 21:48:57 GMT References: <586@dptechno.UUCP> Organization: Information Technology Center, Carnegie Mellon, Pittsburgh, PA Lines: 54 In-Reply-To: <586@dptechno.UUCP> Excerpts from netnews.comp.lang.c: 21-Sep-90 Why use (void) func() ? Dave Lee@dptechno.uucp (1070) > Given a simple function like : > int func(){ ... } > Whose return value I rarely care about --- say printf(). > Why should I go to the extra trouble to write > (void) printf("hello world\n"); [.....] > If I wanted to check the return value, I would have. > This is not the sort of thing that results from a typo or unconcious omission. > I never type > func_call(); > > When I mean > if( func_call() == whatever ) ...; > I never "accidently" ommit a check for return value, though I may be > lazy and decide to omit one. I believe this is a programming > consideration, not a language one. a) You make the traditional assumption that just because YOU never do anything wrong (exagerated emphasis) that NOBODY would ever do something wrong. It's an imperfect world, and mistakes happen. b) Most of the cases of such functions are probably throwbacks to olden days when: -) they didn't have void. -) they almost never bothered to declare anything that was, or returned int. -) they may have actually had a real reason for sending the return value. 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 I change them all from "printf" to "PRINTF" and declare a macro like: #define PRINTF (void)printf It's not beautiful, but at least it shows anyone who looks at my code (including myself some days down the road) that I explicitly decided to ignore the return value. But then we breach into the holliest of holy wars -- (oh noooooo! :0 oh yes! ;-)) -- styles and code formatting. And so, adding my $0.02 to the pot, I return to the murky depths of my own subconcious............ --fish