0

I see below code (with some omission):

int fwts_fault_catch(void);

int main(int argc, char **argv)
{
    (void)fwts_fault_catch(); // <======== HERE
    //...
}

So it seems the function invoking explicitly overrides the return type of the declared function prototype from int to void. Why doing this?

I did some test with below code:

int func1(void){
    return 1;
}

int main(int argc, char** argv){
    func1(); // line 2
    (void)func1(); // line 1
}

I check the assembly code generated with gcc for line 1 and 2 respectively. But there's no difference.

So, what's the (void) for?

smwikipedia
  • 61,609
  • 92
  • 309
  • 482
  • 1
    A developer's acknowledgment that he/she has ignored the return value – Shloim Sep 11 '16 at 08:08
  • 1
    ...otherwise lint-type tools that scan code for validations can/will flag it as a potential logic problem. – WhozCraig Sep 11 '16 at 08:09
  • 1
    Note that you asked a [very similar question](http://stackoverflow.com/questions/39307858/whats-this-usage-of-the-variable-cast-to-void-in-function-body) just a few days ago. – Oliver Charlesworth Sep 11 '16 at 08:10
  • @OliverCharlesworth I didn't realize that question is similar to this. Thanks for pointing it out. Yes, both usage have a pedantic smell. – smwikipedia Sep 11 '16 at 08:13

0 Answers0