I am working on a macro that will support error handling.
#define Try(e, call) ( (e == OK) && ((e = call) != OK) )
It can be used as an expression of an if statement:
if (Try(err, SomeFunction(foo, bar))) {
The function will not be called if err already out of order before the if-statement. After if-statement err is set to the return value of SomeFunction() .
So far so good. However, I also want to use a macro without if-statement:
Try(err, SomeFunction(foo, bar));
In this case, GCC gives the following warning:
warning: value computed is not used [-Wunused-value]
And that is my question: how can I rewrite a macro so that GCC does not give this warning. I know that a warning can be disabled using a flag (but I want it to be enabled for other code) or by explicitly expressing the result to void . The following instruction code will not raise a warning:
(void) Try(err, SomeFunction(foo, bar));
But it is far from ideal to prefix each Try() with void . Any suggestions?
source share