Re: Question about #define

From: CBFalconer (cbfalconer_at_yahoo.com)
Date: 03/01/04


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!


Relevant Pages

  • Re: C Preprocessor with MIPSpro Compilers: Version 7.30
    ... >I use this macro to include generated images in my cc files like this ... You are using a gcc extension. ... Of course a compiler is free to do more, ... Your code is not standard conforming, the IRIX compiler is doing ok ...
    (comp.sys.sgi.misc)
  • Re: Challenging macro with default value
    ... >> macro definition. ... The Intel compiler is front-end compatible with gcc, ... The Sun C compiler on Solaris, when invoked in conforming mode: ...
    (comp.lang.c)
  • Re: Challenging macro with default value
    ... >> macro definition. ... The Intel compiler is front-end compatible with gcc, ... The Sun C compiler on Solaris, when invoked in conforming mode: ...
    (comp.lang.cpp)
  • Re: A Portable C Compiler
    ... it seems unlikely that PCC will be able to generate as good code as GCC ... This means that a compiler that slows down the development process by just 30-60 seconds per build, it is taking between 15-30 minutes per day ... buggy code to one which is not so light but produces strong, ... A simpler compiler is surely easier to debug you see? ...
    (comp.lang.c)
  • Re: Empty statement
    ... > In the release version (DEBUG is an empty statement), ... If the compiler is half-decent, it will of course generate no code for ... the compiler has to generate the code for this macro. ...
    (comp.lang.c)

Loading