Re: Question about #define
From: CBFalconer (cbfalconer_at_yahoo.com)
Date: 03/01/04
- Next message: Rob Johnson: "Re: 'erf' function in C"
- Previous message: Leor Zolman: "Re: Question about #define"
- In reply to: Jorge Naxus: "Question about #define"
- Next in thread: Mark Henning: "Re: Question about #define"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 01 Mar 2004 15:47:01 GMT
Jorge Naxus wrote:
>
> I would like to write a macro like that:
>
> #ifdef DEBUG
> #define printj(...) printf(...)
> #else
> #printj(...)
> #endif
>
> So that printj behaves exactly like printf when DEBUG is true and
> doesnt do anything when DEBUG is false. But I dont know how to
> deal with the variable number of arguments of printf(...).
>
> Any help on how should be my "define"??
You have two choices.
1. Get and use a C99 compiler. Then your code will no longer port
to a C90 compiler.
2. Get and use gcc and the gnu variadic macro extensions. Then
your code will no longer port to a non-gnu compiler. If you get a
late enough gcc you can combine with option 1, because the latest
gccs handle C99 variadic macros in addition to the gnu flavor.
The only example I can show you is in nmalloc.zip, available on my
page, download section. It is using exactly those facilities, and
is thus limited to gcc compilation.
-- Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net) Available for consulting/temporary embedded and systems. <http://cbfalconer.home.att.net> USE worldnet address!
- Next message: Rob Johnson: "Re: 'erf' function in C"
- Previous message: Leor Zolman: "Re: Question about #define"
- In reply to: Jorge Naxus: "Question about #define"
- Next in thread: Mark Henning: "Re: Question about #define"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|