Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22015

use macro to test function return value in C

$
0
0

I want to have a macro which does something like:

#define TEST(_ptr) ({ if ((_ptr) == NULL) ERROR; (_ptr); })

which check _ptr and calls ERROR macro or return its value.

However, if I use something like var = TEST(fun()) this results in fun() being called two times.

I can do something like:

#define TEST(_tmp, _ptr) ({ _tmp = _ptr; if ((_tmp) == NULL) ERROR; (_tmp); })

is there any clean way of doing this without passing temporary storage, e.g. using typeof operator!?


Viewing all articles
Browse latest Browse all 22015

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>