views:

22

answers:

3

Hi Folks.

To completely disable a debug output in c-source, I usually define the following SIMPLE macro #1

#define dprintf(args)

To enable a debug output, I define macro #2 alternatively

#define dprintf(args) printk##args

The usage in source looks like:

dprintf(("Irqs:%lu\n",irqs));

A preprocessor should create following line if I use macro #2

printk("Irqs:%lu\n",irqs);

Under Windows Visual c++, there is no problem.

Using gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu9) under NETBEANS IDE 6.8, I got the following error message:

"printk" and "(" does not give a valid preprocessing token

I tried the following under Linux

#define dprintk(args...) printk(args)

This works only with dprintf("Irqs:%lu\n",irqs);

Visual c++ however does not know args...

I have to compile source code on windows and Linux(386) platform alternatively.

Does anyone have an idea ?

Best regards, Yves Ferrant

+2  A: 

Why not #define dprintf(args) print args ?

The double parenthesis could have been added to replace the variadic macro in visual C++ : the preprocessor will handle macro invocation as if there was only one parameter.

philippe
A: 

The token pasting operator ## can only be used to concatenate tokens, as its name implies. Some compilers, e.g. newer versions of gcc, enforce this more rigidly than others, as you have now discovered. As philippe says, though, you don't actually need ## in this particular example.

Paul R
A: 

Thanks a lot philippe and Paul R for your extremely quick answers.

I tried it out under Linux just wondering in face of a miracle.

The easiest way seems to be always the best.

Best Regards, Yves Ferrant.

Yves Ferrant