I want to extend minunit to be more useful, with the macro.
#define mu_assert_equal(actual, expected) do { \
if (actual != expected) { \
char *message = malloc(MAX_ERROR_MESSAGE_LENGTH); \
if (message == NULL) { printf("malloc failed"); exit(1); } \
snprintf(message, MAX_ERROR_MESSAGE_LENGTH, "required: %s != %s, reality: %s == %lu", \
#actual, #expected, #actual, actual); \
return message; \
} \
} while (0)
invoked with:
mu_assert_equal(bytes_parsed, 1);
but the macro above only works for unsigned long values.
How I can I find the type of the macro arguments, and more importantly, their printf specifiers.
Without generics, perhaps the best would be different macros for your different types:
and invoke as:
(Edited in light of comment to also pass the test to the "generic" test).
You can't, in C before C11 (which adds generics).
There's no way to compute the type of an expression in C, which is what you would need to do. If it were possible, then
printf()
wouldn't need to have static specifiers in the first place, more or less.