1

I have a macro that is defined as the following, ie:

#define next_position() (bit ? *str++ : (*str++) & 0xff)

warning: expression result unused [-Wunused-value]

Clang is saying the first *str++ is being unused in the macro, but gcc never displayed this 'warning' to me, is this a compiler bug? how can I work around it? It seems like a legitimate warning.

7
  • Where are you using next_position? Are you just writing next_position(); without using the expression result? clang, like any other C compiler, doesn't complain about macros themselves, only macro instantiations. Commented Sep 28, 2012 at 3:45
  • In say, help.c, I'm just calling it like next_position() Commented Sep 28, 2012 at 3:46
  • 2
    What I'm getting at is this: are you using the output of next_position? If you aren't, then the warning makes perfect sense. It's not warning about *str++, but about next_position as a whole. Commented Sep 28, 2012 at 3:48
  • I ended up just doing this next_position(*str++) and getting rid of some rough calls in my code. Thanks! Commented Sep 28, 2012 at 3:56
  • 2
    Casting to void, as in (void)(bit ? *str++ : (*str++) & 0xff) would take care of it. Commented Sep 28, 2012 at 5:23

1 Answer 1

1

Clang is correct -- you are dereferencing str, but are not using its value. If all you want is to advance str, then next_position would boil down to:

#define next_position() str++

It would bring the question why you would want to hide that behind a macro, but that's a different issue.

As for getting warning from clang, but not gcc, they are different compilers. They are detecting overlapping but not identical set of potential issues with the code and they are pedantic in somewhat different ways. Even gcc itself produces different sets of warnings depending on optimization level and gcc version. The fact that one compiler produces a warning but another does not does not necessarily mean that there's a bug in the compiler. Nor does it say anything whether there's really a problem in your code. It's just an indication that something may be off.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.