hassle with macro

M

Mark

I have a piece of code having these lines:

#define ET_ERROR(args) fprintf(args)
....
ET_ERROR(("bus %d slot %d", bus, slot)); /* XX */

This causes compilation warnings:

warning: left-hand operand of comma expression has no effect
warning: passing argument 1 of 'printf' makes pointer from integer without a
cast

Obviously the second is the consequence of the first. As Im understand the
compiler treats expression found in parentheses of printf as a comma
operator. Is there any way to make it work, except changing a number of
arguments to macro, as there are lots of such macros scattered around the
code?
 
B

Ben Pfaff

Mark said:
I have a piece of code having these lines:

#define ET_ERROR(args) fprintf(args)
...
ET_ERROR(("bus %d slot %d", bus, slot)); /* XX */

If ET_ERROR is intended to be invoked that way, then it should be
defined this way:
#define ET_ERROR(args) fprintf args
 
M

Mark

Ben said:
If ET_ERROR is intended to be invoked that way, then it should be
defined this way:
#define ET_ERROR(args) fprintf args
Thank you very much indeed!
 
R

Ralf Damaschke

Ben said:
If ET_ERROR is intended to be invoked that way, then it should be
defined this way:
#define ET_ERROR(args) fprintf args

Hmm, if ET_ERROR is intended to be invoked that way, then it should
better be defined this way:

#define ET_ERROR(args) printf args

-- Ralf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,817
Latest member
AdalbertoT

Latest Threads

Top