On Tue, 15 Mar 2005 11:58:31 -0500, Mario Charest wrote:
Anyone knows a trick to get macro with variable number of argument:
#define DEBUG_PRINT(format, …) debug_print( FILE, LINE,
format, …)
Watcom doesn’t support the … and I’m looking for a way to acheive the
same idea, but so far my brain has been unable to come up with anything
decent.
Hi Mario,
I have seen other people’s code just do this kind of trick before:
#define DEBUG_PRINT_0(format)
debug_print(FILE,LINE, format)
#define DEBUG_PRINT_1(format, arg1)
debug_print(FILE,LINE,format,arg1)
#define DEBUG_PRINT_2(format, arg1, arg2)
debug_print(FILE,LINE,format,arg1,arg2)
…
and so on up to the maximum possible number of args
Personally I’m not a fan but I don’t know of a better solution in C.
In C++ it is easy, you can just do
#define DEBUG
cout << "debug: " << FILE << “:” << LINE << “:”
then in your code:
DEBUG << message << arg1 << arg2 << endl;
Rob Rutherford