steve@groucho.ucar.edu (Steve Emmerson) (05/26/90)
I'd like to poll this group's readership on the following question: Aside from getting lint(1) to shut up, why else would one write (void)printf(fmt); rather than the simpler printf(fmt); ? NB: This question is intended to be neutral. Steve Emmerson steve@unidata.ucar.edu ...!ncar!unidata!steve
henry@utzoo.uucp (Henry Spencer) (05/27/90)
In article <7486@ncar.ucar.edu> steve@groucho.ucar.edu (Steve Emmerson) writes: >Aside from getting lint(1) to shut up, why else would one write > (void)printf(fmt); >rather than the simpler > printf(fmt); Personally, this is one of the few places where I just refuse to use the cast. I consider it pointless clutter. If lint objects, tough. In the (relatively rare) event that I seriously care whether printf output got out intact (fprintf output I often care about, but not printf), I check ferror(stdout) afterwards. That also lets me do one check after a number of printfs, and avoids portability hassles over the return values. -- Life is too short to spend | Henry Spencer at U of Toronto Zoology debugging Intel parts. -Van J.| uunet!attcan!utzoo!henry henry@zoo.toronto.edu
brnstnd@stealth.acf.nyu.edu (05/28/90)
In article <1990May27.001120.13623@utzoo.uucp> henry@utzoo.uucp (Henry Spencer) writes: > In article <7486@ncar.ucar.edu> steve@groucho.ucar.edu (Steve Emmerson) writes: > >Aside from getting lint(1) to shut up, why else would one write > > (void)printf(fmt); > >rather than the simpler > > printf(fmt); > Personally, this is one of the few places where I just refuse to use the > cast. I consider it pointless clutter. If lint objects, tough. When I'm not checking a return value but know I should, I'll express that by writing ``if (...) ; /*XXX*/''. When I'm not checking a return value and don't see a need to, I'll express that by writing (void). When I think that a return value is totally pointless, I'll express that by defining a macro with the (void). Just as I find XXX useful to mark code needing more work, I find (void) useful to mark an ignored return value, no matter how unimportant. Later on I can use these hints to quickly search through my code for possible trouble spots. (Getting lint to shut up is useful in its own right: I regularly run my code through lint -haxc (and sometimes gcc -Wall -ansi -pedantic), and I want as few distractions as possible.) ---Dan
harrison@necssd.NEC.COM (Mark Harrison) (06/02/90)
In article <1990May27.001120.13623@utzoo.uucp>, henry@utzoo.uucp (Henry Spencer) writes: > In article <7486@ncar.ucar.edu> steve@groucho.ucar.edu (Steve Emmerson) writes: > >Aside from getting lint(1) to shut up, why else would one write > > (void)printf(fmt); > >rather than the simpler > > printf(fmt); > Personally, this is one of the few places where I just refuse to use the > cast. I consider it pointless clutter. If lint objects, tough. I agree. One of the nice things about using {PC,Flexe}Lint from Gimpel Software is that you can selectively turn off/on specific checks for specific functions (i.e. "Don't tell me when I ignore the return value from printf."). They put the fun back into running lint! :-) If you would like more information, their number is (215)584-4261. Tell them I sent you and they'll treat you right ;-). -- Mark Harrison harrison@necssd.NEC.COM (214)518-5050 {necntc, cs.utexas.edu}!necssd!harrison standard disclaimers apply...