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!?