This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: selective function call


Hayim Shaul wrote:

> But this is very tiring.
> I created a MACRO
> 
>         #define LOG if (logger->is_activated()) logger->print
> 
> and use it:
>         LOG("%d\n", ackerman(5,5));

How about:

#define LOG(fmt, ...) if (logger->is_activated()) \
                        logger->print (fmt, ## __VA_ARGS__)

Note that using ## here is a gcc-specific extension that allows for
calling LOG("foo") without following parameters, which would otherwise
cause an error under C99.

Brian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]