I'm currently using the following statement to get assert and printf to work together, is there any better way to do this?
#define ASSERT(x) for(; !(x); assert(x))
#define ALLOC_CHECK(x, ...) ASSERT(x) printf(__VA_ARGS__ "\n");
ALLOC_CHECK(ptr != NULL, "Pointer not initialized");
You don't need to whip up your own assert() variant, you can just include an error message in the assert itself:
assert(someCondition && "Internal error: ... . Please report this bug.");
Since the assert() macro prints its argument on failure, it will also print your string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With