Re:Nweb: a tiny, safe web server (static pages only)
by theseoafs on Tuesday April 01, 2014 @03:09AM
(#7506603)
Nothing about the cast is "required". However, it's good practice because the cast explicitly acknowledges the function has a return value that we're throwing out. Looking at the following function call:
(void)create_widget(&widget);
It's clear that `create_widget` returns some value -- it's probably an error code that tells us whether the widget creation was successful. The source code here says "I know this function returns an important value, but I'm going to disregard it here". This could be useful for debugging if you find that, for example, an error condition is being handled improperly (e.g. "oh, we're obviously throwing out the return value of this function, which we shouldn't be doing"). This function call is much less informative: create_widget(&widget);
Re:Nweb: a tiny, safe web server (static pages only)
by tptacek on Tuesday April 01, 2014 @09:23AM
(#7507891)
It's a terrible and (I think) amateurish practice that misapprehends the point of C's type checking while adding lots of visual noise, which is why you'll virtually never see it in well-liked C code.
Does extremely pedantic C require the results of function calls to be used?
I know the correct way to mark a variable as unused is to cast it to void, but I'm not sure if you're supposed to do that for function return values as well.