I'm working on a custom unit-testing framework that doesn't display the filename/line numbers of failed tests. I know I could require them as arguments for the report_results function but that seems like a lot of text.
Is there a way to make it so that __FILE__ and __LINE__ are always passed with the function, even if I don't pass them when I call it?
You can do something like this in C++:
void func(char *file=__FILE__, int line=__LINE__)(int more_args) {}
use a macro in your code, to call an underlying function
#define func(arg) real_func(__FILE__,__LINE__,arg)
where real_func is
void real_func(const char *file, int line, int arg);
In your code, when you call func(12), it expands to a call to real_func, with actual file path and line of the call. You can even support variable argument functions in C99 with variadic macros as a frontend.
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