2

How can I disable this kind of warning -

Comparison of constant -1 with expression of type 'int' is always true

It would appear for a code like this -

int x = -1;

if (x == -1)
     // do stuff

So, how can I suppress this warning?

I can see a list of warnings to suppress in the Build Settings section of my target, went over them one by one but either I'm missing it or it's not there -

build settings warning options 1 build settings warning options 2 build settings warning options 3

If it's not there, is there a compiler flag I can pass to suppress it?

Kof
  • 23,893
  • 9
  • 56
  • 81
  • You could use something from this answer, but it is slightly outdated (2008) http://stackoverflow.com/questions/194666/is-there-a-way-to-suppress-warnings-in-xcode – erdekhayser Sep 14 '13 at 16:51
  • @H2CO3 Showing the actual code won't help answering the question, which is "how to suppress the warning?". :) – Kof Sep 14 '13 at 19:29
  • 6
    @Kof Nah. You don't *suppress* the warning, you *fix* it. **Show actual code.** –  Sep 14 '13 at 19:30
  • There ya go, the actual code. – Kof Sep 14 '13 at 19:53
  • @Kof Thanks. Why would you do things like this? `int foo = -1; if (fo == -1)` is redundant. If you want to suppress this warning, perhaps you can find something in clang's manual, something like `-Wno-tautological-comparison` is what might be relevant. –  Sep 14 '13 at 20:09
  • I agree with H2CO3. Bad idea to surpress warnings, they help you find lots of different kinds of bugs. Better to *fix* the code. What are you actually trying to do with this code? – BergQuester Sep 15 '13 at 00:26
  • There's nothing to fix, the code is an example for how to reproduce the warning. I want to know how to suppress this warning. – Kof Sep 15 '13 at 04:30
  • 2
    I got here to find an answer to this question and what I found here? People bickering around about missing code. Kof has a point, sometimes it happens that a warning is not relevant. I am using a macro and this confused the compiler, so the warning is useless. – nalply Jun 04 '15 at 08:48
  • 1
    +1 to finding nothing useful here. In this case, this was in source provided by an external party that you'd typically have no intention of modifying and trying to understand the intricacies of. – Guykun Feb 24 '16 at 05:10

0 Answers0