I've never liked having to type my test twice, once for the actual test and once for the 'message'. So I do something more like this instead:
#include <stdio.h>
#define test(expr) do { \
if (!(expr)) printf("FAILED: %s\n", #expr); \
else printf(" ok: %s\n", #expr); \
} while (0)
int main(void) {
int a = 1;
test(a == 1);
test(a == 0);
return 0;
}
I don't actually use the direct printf() approach, but this shows the idea. Is there a reason more people don't 'stringify' macro arguments? I'm pretty tied to GCC, and am not always aware of what works on other compilers.