hassle with macro

Discussion in 'C Programming' started by Mark, Apr 26, 2010.

  1. Mark

    Mark Guest

    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?

    --
    Mark
    Mark, Apr 26, 2010
    #1
    1. Advertising

  2. Mark

    Ben Pfaff Guest

    "Mark" <> writes:

    > 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
    --
    Ben Pfaff
    http://benpfaff.org
    Ben Pfaff, Apr 26, 2010
    #2
    1. Advertising

  3. Mark

    Mark Guest

    Ben Pfaff wrote:
    >> 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

    Thank you very much indeed!

    --
    Mark
    Mark, Apr 26, 2010
    #3
  4. Ben Pfaff wrote:

    > "Mark" <> writes:
    >
    >> 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


    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
    Ralf Damaschke, Apr 26, 2010
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SparvHok

    Postback, a hassle!?

    SparvHok, Dec 7, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    496
    Patrice
    Dec 7, 2004
  2. Paul Watt

    hassle with layout

    Paul Watt, Apr 4, 2006, in forum: HTML
    Replies:
    3
    Views:
    350
    Paul Watt
    Apr 4, 2006
  3. kanzen
    Replies:
    7
    Views:
    385
    =?ISO-8859-1?Q?Gerhard_H=E4ring?=
    Mar 23, 2005
  4. Evan Kroske

    Python 2.6 worth the hassle?

    Evan Kroske, May 6, 2009, in forum: Python
    Replies:
    1
    Views:
    270
    Steven D'Aprano
    May 7, 2009
  5. Mirco Wahab

    substr() hassle, *n*x vs. Win32

    Mirco Wahab, Jun 14, 2006, in forum: Perl Misc
    Replies:
    4
    Views:
    171
Loading...

Share This Page