I use a return integer to propagate errors through my code. I would like gcc
to provide me with a warning if I accidentally forget to propagate the error (i.e. when I forget to use the return integer).
Consider this very simple example test.c
:
// header
int test ( int a );
// function
int test ( int a )
{
if ( a<0 ) return 1;
return 0;
}
// main program
int main ( void )
{
int a = -10;
test(a);
return 0;
}
$ gcc -Wunused-result main.c
Warning: main.c:19 ... unused return ...
or alternatively using Wall
or Wextra
or another option.
Needless to say, my compiler does not provide the warning with any of these options. One of my mistakes already took me frustratingly long to find...
// header
int test ( int a ) __attribute__ ((warn_unused_result));
// function
int test ( int a )
{
if ( a<0 ) return 1;
return 0;
}
// main program
int main ( void )
{
int a = -10;
test(a);
return 0;
}
It should work now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With