Suppressing Compiler Warning About Tricky Macro

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael B Allen

    #1

    Suppressing Compiler Warning About Tricky Macro

    Hi,

    I have a macro that looks like the following:

    #define MMSG msgno_loc0(LOC0 , LOC1) && msgno_mmsg0

    which if used in some code like:

    MMSG("foo=%s", foo);

    would expand to [1]:

    loc0(LOC0, LOC1) && msgno_mmsg0("fo o=%s", foo);

    My problem is that the GCC 64 bit compiler complains about this with:

    warning: value computed is not used

    Can someone recommend a change that can eliminate these warnings?

    I'm drawing a blank.

    Mike

    [1] LOC0 and LOC1 are not shown expaned for the sake of simplicity
  • Robert Gamble

    #2
    Re: Suppressing Compiler Warning About Tricky Macro

    On Jul 21, 10:52 pm, Michael B Allen <iop...@gmail.c omwrote:
    Hi,
    >
    I have a macro that looks like the following:
    >
    #define MMSG msgno_loc0(LOC0 , LOC1) && msgno_mmsg0
    >
    which if used in some code like:
    >
    MMSG("foo=%s", foo);
    >
    would expand to [1]:
    >
    loc0(LOC0, LOC1) && msgno_mmsg0("fo o=%s", foo);
    >
    My problem is that the GCC 64 bit compiler complains about this with:
    >
    warning: value computed is not used
    >
    Can someone recommend a change that can eliminate these warnings?
    The warning doesn't appear to be coming from the preprocessor. The
    fully expanded version probably contains an expression who value is
    discarded, without seeing the fully expanded version (and possibly the
    appropriate associated definitions) it is difficult to determine
    exactly where the problem is.

    Robert Gamble

    Comment

    • Abdo Haji-Ali

      #3
      Re: Suppressing Compiler Warning About Tricky Macro

      On Jul 22, 4:52 am, Michael B Allen <iop...@gmail.c omwrote:
      Hi,
      >
      I have a macro that looks like the following:
      >
      #define MMSG msgno_loc0(LOC0 , LOC1) && msgno_mmsg0
      >
      which if used in some code like:
      >
      MMSG("foo=%s", foo);
      >
      would expand to [1]:
      >
      loc0(LOC0, LOC1) && msgno_mmsg0("fo o=%s", foo);
      >
      My problem is that the GCC 64 bit compiler complains about this with:
      >
      warning: value computed is not used
      >
      Can someone recommend a change that can eliminate these warnings?
      #define MMSG_MODIFIED msgno_loc0(LOC0 , LOC1); msgno_mmsg0

      OR:

      bool bValue = MMSG("foo=%s", foo);

      Note that this line:
      loc0(LOC0, LOC1) && msgno_mmsg0("fo o=%s", foo);
      (actually should be: msgno_loc0(LOC0 , LOC1) && msgno_mmsg0("fo o=%s",
      foo); )

      Calls two functions msgno_loc0 and msgno_mmsg0 which in turn return
      (supposably) bool values
      These two boolean values are ANDed with the && operator and the final
      ADDed value is discarded since you're not
      assigning it to another variable nor using it in a if condition.

      Abdo Haji-Ali
      Programmer
      In|Framez

      Comment

      • Michael B Allen

        #4
        Re: Suppressing Compiler Warning About Tricky Macro

        On Sun, 22 Jul 2007 03:38:13 -0000
        Robert Gamble <rgamble99@gmai l.comwrote:
        On Jul 21, 10:52 pm, Michael B Allen <iop...@gmail.c omwrote:
        Hi,

        I have a macro that looks like the following:

        #define MMSG msgno_loc0(LOC0 , LOC1) && msgno_mmsg0

        which if used in some code like:

        MMSG("foo=%s", foo);

        would expand to [1]:

        msgno_loc0(LOC0 , LOC1) && msgno_mmsg0("fo o=%s", foo);
        ^^^^^^corrected

        My problem is that the GCC 64 bit compiler complains about this with:

        warning: value computed is not used

        Can someone recommend a change that can eliminate these warnings?
        >
        The warning doesn't appear to be coming from the preprocessor. The
        fully expanded version probably contains an expression who value is
        discarded, without seeing the fully expanded version (and possibly the
        appropriate associated definitions) it is difficult to determine
        exactly where the problem is.
        Hi Robert,

        The LOC0 and LOC1 macros just expand to a filename, line number and
        possibly a function name.

        The msgno_loc0 and msgno_mmsg0 symbols are functions. Additionally
        msgno_loc0 function always returns 1.

        What I did do that seems to be ok for now is:

        #define MMSG if (msgno_loc0(LOC 0, LOC1)) msgno_mmsg0

        but in hind sight now I'm not entirely clear as to why I didn't just do:

        #define MMSG msgno_loc0(LOC0 , LOC1); msgno_mmsg0

        Mike

        Comment

        • Barry Schwarz

          #5
          Re: Suppressing Compiler Warning About Tricky Macro

          On Sat, 21 Jul 2007 22:52:28 -0400, Michael B Allen <ioplex@gmail.c om>
          wrote:
          >Hi,
          >
          >I have a macro that looks like the following:
          >
          #define MMSG msgno_loc0(LOC0 , LOC1) && msgno_mmsg0
          >
          >which if used in some code like:
          >
          MMSG("foo=%s", foo);
          >
          >would expand to [1]:
          >
          loc0(LOC0, LOC1) && msgno_mmsg0("fo o=%s", foo);
          No, but hopefully it is just a typo. The left operand of the &&
          operator would be
          msgno_loc0(LOC0 , LOC1)
          It is important to cut and paste the code, not retype it.
          >
          >My problem is that the GCC 64 bit compiler complains about this with:
          >
          warning: value computed is not used
          Look at the above statement. The && operator evaluates its left
          operand. If not zero, it evaluates the right operand. If that is
          also not zero, the result is set to 1. If either operand is zero, the
          result is set to 0. But the result is NEVER used. It is not assigned
          to a variable; it is not part of an if/while/?:/for construct. After
          going through the trouble of calling the first function, calling the
          second function (only if the first returns a non-zero value), and
          computing the boolean AND, the result is thrown in the bit bucket,
          never to be seen again.

          If either of the two functions have side effects, this may be a
          reasonable thing to do. However, in general, it's not.
          >
          >Can someone recommend a change that can eliminate these warnings?
          There are two obvious (to me) ways to silence the warning.

          If you care about the result, assign it to a variable or use
          it in one of the conditional constructs.

          If you don't care about the result of the expression but only
          about the side effects of the function calls, then change the macro to
          something like

          #define MMSG \
          if (msgno_loc0(LOC 0, LOC1)) \
          msgno_mmsg0

          Since you chose to have the arguments to msgno_mmsg0 outside the
          macro, you cannot define the macro expansion with the usual
          do(...)while(0) ; construct.


          Remove del for email

          Comment

          • Eric Sosman

            #6
            Re: Suppressing Compiler Warning About Tricky Macro

            Michael B Allen wrote:
            On Sun, 22 Jul 2007 03:38:13 -0000
            Robert Gamble <rgamble99@gmai l.comwrote:
            >
            >On Jul 21, 10:52 pm, Michael B Allen <iop...@gmail.c omwrote:
            >>Hi,
            >>>
            >>I have a macro that looks like the following:
            >>>
            >> #define MMSG msgno_loc0(LOC0 , LOC1) && msgno_mmsg0
            >>>
            >>which if used in some code like:
            >>>
            >> MMSG("foo=%s", foo);
            >>>
            >>would expand to [1]:
            >>>
            >> msgno_loc0(LOC0 , LOC1) && msgno_mmsg0("fo o=%s", foo);
            ^^^^^^corrected
            >>My problem is that the GCC 64 bit compiler complains about this with:
            >>>
            >> warning: value computed is not used
            >>>
            >>Can someone recommend a change that can eliminate these warnings?
            >The warning doesn't appear to be coming from the preprocessor. The
            >fully expanded version probably contains an expression who value is
            >discarded, without seeing the fully expanded version (and possibly the
            >appropriate associated definitions) it is difficult to determine
            >exactly where the problem is.
            >
            Hi Robert,
            >
            The LOC0 and LOC1 macros just expand to a filename, line number and
            possibly a function name.
            >
            The msgno_loc0 and msgno_mmsg0 symbols are functions. Additionally
            msgno_loc0 function always returns 1.
            >
            What I did do that seems to be ok for now is:
            >
            #define MMSG if (msgno_loc0(LOC 0, LOC1)) msgno_mmsg0
            >
            but in hind sight now I'm not entirely clear as to why I didn't just do:
            >
            #define MMSG msgno_loc0(LOC0 , LOC1); msgno_mmsg0
            Probably because both of these will produce unpleasant
            surprises in contexts like

            if (phaseOfMoon == FULL)
            MMSG("foo=%s", foo);
            else
            MMSG("bar=%s", bar);

            --
            Eric Sosman
            esosman@ieee-dot-org.invalid

            Comment

            • Barry Schwarz

              #7
              Re: Suppressing Compiler Warning About Tricky Macro

              On Sun, 22 Jul 2007 12:07:33 -0400, Michael B Allen <ioplex@gmail.c om>
              wrote:
              >On Sun, 22 Jul 2007 03:38:13 -0000
              >Robert Gamble <rgamble99@gmai l.comwrote:
              >
              >On Jul 21, 10:52 pm, Michael B Allen <iop...@gmail.c omwrote:
              Hi,
              >
              I have a macro that looks like the following:
              >
              #define MMSG msgno_loc0(LOC0 , LOC1) && msgno_mmsg0
              >
              which if used in some code like:
              >
              MMSG("foo=%s", foo);
              >
              would expand to [1]:
              >
              msgno_loc0(LOC0 , LOC1) && msgno_mmsg0("fo o=%s", foo);
              ^^^^^^corrected
              >
              My problem is that the GCC 64 bit compiler complains about this with:
              >
              warning: value computed is not used
              >
              Can someone recommend a change that can eliminate these warnings?
              >>
              >The warning doesn't appear to be coming from the preprocessor. The
              >fully expanded version probably contains an expression who value is
              >discarded, without seeing the fully expanded version (and possibly the
              >appropriate associated definitions) it is difficult to determine
              >exactly where the problem is.
              >
              >Hi Robert,
              >
              >The LOC0 and LOC1 macros just expand to a filename, line number and
              >possibly a function name.
              >
              >The msgno_loc0 and msgno_mmsg0 symbols are functions. Additionally
              >msgno_loc0 function always returns 1.
              >
              >What I did do that seems to be ok for now is:
              >
              #define MMSG if (msgno_loc0(LOC 0, LOC1)) msgno_mmsg0
              >
              >but in hind sight now I'm not entirely clear as to why I didn't just do:
              >
              #define MMSG msgno_loc0(LOC0 , LOC1); msgno_mmsg0
              Maybe because you subconsciously realized that they are not
              equivalent. In the first case, msgno_mmsg0 is called only if
              msgno_loc0 returns a non-zero value. In the second, msgno_mmsg0 is
              called unconditionally .


              Remove del for email

              Comment

              Working...