i found this code from here
#if 1
#define rsAssert(v) do {if(!(v)) LOGE("rsAssert failed: %s, in %s at %i", #v, __FILE__, __LINE__);} while(0)
#else
#define rsAssert(v) while(0)
#endif
Question 1:
Here i am not getting why do and while is used here? Is there any special reason for using this?
Question 2:
What is the purpose of doing this all in macro. Why just one dont use assert() ?
i think perhaps there is a valid reason for this..
The do/while is a well-known trick for turning a block of statements into something that syntactically acts like a single statement. It allows use in places like:
whereas, most alternatives would produce a syntax error in this case.
As for why using it at all: because it writes output with
LOGEinstead of printing tostderr, and (unless LOGE does so) this doesn’t seem to abort the program likeassertwill.