Watcom C

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.

  • Mario

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.

  • Mario

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

“Mario Charest” postmaster@l127.0.0.1 wrote in message
news:d17430$mm9$1@inn.qnx.com

Anyone knows a trick to get macro with variable number of argument:

#define DEBUG_PRINT(format, …) debug_print( FILE, LINE, format,
…)

How about

#define DEBUG_PRINT (debug_file=FILE, debug_line=LINE,debug_print)

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.

  • Mario

How about something like:

#define DEBUG_PRINT(str)
printf("%s %d ", FILE, LINE) ; printf str ; fflush(stdout);

DEBUG_PRINT (("%s %s\r\n", “Hello”, “World”))

Len.

Len Meakin wrote:

How about something like:

#define DEBUG_PRINT(str)
printf("%s %d ", FILE, LINE) ; printf str ; fflush(stdout);

DEBUG_PRINT (("%s %s\r\n", “Hello”, “World”))

I’d suggest using commas and parentheses instead of the semicolons:

#define DEBUG_PRINT(str)
(printf("%s %d ", FILE, LINE), printf str, fflush(stdout))

to allow things like this:

if ( foo == 0 )
if ( bar == 0 )
do_something();
else
DEBUG_PRINTF(( “bar=%d\n”, bar ));
else
DEBUG_PRINTF(( “foo=%d\n”, foo ));

“Wojtek Lerch” <Wojtek_L@yahoo.ca> wrote in message
news:d19kg9$hub$1@inn.qnx.com

Len Meakin wrote:
How about something like:

#define DEBUG_PRINT(str)
printf("%s %d ", FILE, LINE) ; printf str ; fflush(stdout);

DEBUG_PRINT (("%s %s\r\n", “Hello”, “World”))

I’d suggest using commas and parentheses instead of the semicolons:

#define DEBUG_PRINT(str)
(printf("%s %d ", FILE, LINE), printf str, fflush(stdout))

to allow things like this:

if ( foo == 0 )
if ( bar == 0 )
do_something();
else
DEBUG_PRINTF(( “bar=%d\n”, bar ));
else
DEBUG_PRINTF(( “foo=%d\n”, foo ));

Thanks to all for the suggestions. Problem solved.!!!