watcom C makro definition

bridged with qdn.public.qnx4
Post Reply
Andreas

watcom C makro definition

Post by Andreas » Sun Dec 07, 2003 11:09 am

#define DEBUG 0

#define(a,b,...c) if (debug >= a) fprintf (stdout,b)



dprint (DEBUG, "blabla\n.");

dprint (DEBUG, "blabla\n %2X %d \n ", aa, bb);

whats wrong?

watcom 10.6

QNX4.25

regards

Andreas

Carlos Clarke

Re: watcom C makro definition

Post by Carlos Clarke » Mon Dec 08, 2003 6:33 pm

On Sun, 7 Dec 2003 12:09:17 +0100, "Andreas" <amathys@bluewin.ch>
wrote:
#define DEBUG 0

#define(a,b,...c) if (debug >= a) fprintf (stdout,b)

As far as I know Watcom doesn't handle variable numbers of arguments
in defines.

dprint (DEBUG, "blabla\n.");

dprint (DEBUG, "blabla\n %2X %d \n ", aa, bb);

whats wrong?

watcom 10.6

QNX4.25

regards

Andreas







Mario Charest

Re: watcom C makro definition

Post by Mario Charest » Mon Dec 08, 2003 8:28 pm

"Carlos Clarke" <carlos@ptdprolog.net> wrote in message
news:0ug9tv04ffmocunq2a7th5pu39mljl4i37@4ax.com...
On Sun, 7 Dec 2003 12:09:17 +0100, "Andreas" <amathys@bluewin.ch
wrote:

#define DEBUG 0

#define(a,b,...c) if (debug >= a) fprintf (stdout,b)

As far as I know Watcom doesn't handle variable numbers of arguments
in defines.
To my knowledge this isn't standard C.

dprint (DEBUG, "blabla\n.");

dprint (DEBUG, "blabla\n %2X %d \n ", aa, bb);

whats wrong?

watcom 10.6

QNX4.25

regards

Andreas








Pete DiMarco

Re: watcom C makro definition

Post by Pete DiMarco » Tue Dec 09, 2003 3:04 am

Previously, Mario Charest wrote in qdn.public.qnx4:
"Carlos Clarke" <carlos@ptdprolog.net> wrote in message
news:0ug9tv04ffmocunq2a7th5pu39mljl4i37@4ax.com...
On Sun, 7 Dec 2003 12:09:17 +0100, "Andreas" <amathys@bluewin.ch
wrote:

#define DEBUG 0

#define(a,b,...c) if (debug >= a) fprintf (stdout,b)

As far as I know Watcom doesn't handle variable numbers of arguments
in defines.

To my knowledge this isn't standard C.
FWIW, I use the following:

#ifdef DEBUG
#define debug_msg fprintf
#else
#define debug_msg (void)
#endif // DEBUG

You'd apply it something like this:

debug_msg(stderr, "Here's x, y, and z: %1d, %1d, %1d.\n", x, y, z);

This macro has a few disadvantages: If there are side-effects
in the parameters, these will occur even when DEBUG is turned off
(which is determined at compile-time, not run-time). Also, the
compiler will complain with:

Warning! W111: Meaningless use of an expression

when DEBUG is turned off. It also wastes some RAM and CPU cycles.
But it's easy to type. :-)

- Pete

--
+----- Pete DiMarco ------+---------------------------------------+
| Staff Software Engineer | Web: www.ifspurity.com |
| Integrated Flow Systems | Email: peted [At] ifspurity [Dot] com |
+-------------------------+---------------------------------------+
<< Opinions expressed here are my own, not those of my employer. >>

Dieter Schemmelmann

Re: watcom C makro definition

Post by Dieter Schemmelmann » Thu Dec 11, 2003 8:20 am

I have a firm solution

#define dprint (a,b) if (debug >= (a)) printf ("%s\n", (b))

int main (int argc, char **argv)
{ int debug = atoi (argv[1]);
dprint (1, "debug message");
return 0;
}

Andreas schrieb:
#define DEBUG 0

#define(a,b,...c) if (debug >= a) fprintf (stdout,b)

dprint (DEBUG, "blabla\n.");

dprint (DEBUG, "blabla\n %2X %d \n ", aa, bb);

whats wrong?

watcom 10.6

QNX4.25

regards

Andreas

Robert Krten

Re: watcom C makro definition

Post by Robert Krten » Thu Dec 11, 2003 2:29 pm

Dieter Schemmelmann <dieschemm@t-online.de> wrote:
I have a firm solution

#define dprint (a,b) if (debug >= (a)) printf ("%s\n", (b))

int main (int argc, char **argv)
{ int debug = atoi (argv[1]);
dprint (1, "debug message");
return 0;
}
I use the following for debug:

// set this for debugging
#define VDebug

#ifdef VDebug
extern int optd;
#define CP { if (optd) fprintf (stdout, "[** %s %d **]\n", __FILE__, __LINE__); }
#define D if (optd > 1)
#else // VDebug
#define CP ;
#define D if (0)
#endif // VDebug

Then, in the source, I can do things like:


code
code
D code that only runs during debug
code

I find the "D" at the beginning of the line unobtrusive.

But, as with any coding style, it's a large part personal preference... :-)

Cheers,
-RK
Andreas schrieb:

#define DEBUG 0

#define(a,b,...c) if (debug >= a) fprintf (stdout,b)

dprint (DEBUG, "blabla\n.");

dprint (DEBUG, "blabla\n %2X %d \n ", aa, bb);

whats wrong?

watcom 10.6

QNX4.25

regards

Andreas
--
[If replying via email, you'll need to click on the URL that's emailed to you
afterwards to forward the email to me -- spam filters and all that]
Robert Krten, PDP minicomputer collector http://www.parse.com/~pdp8/

Post Reply

Return to “qdn.public.qnx4”