Can anybody please tell me which flag I have to use in order to make gcc ignore the 'comparison between signed and unsigned integer expressions' warning message.
Asked
Active
Viewed 3.5k times
2 Answers
54
gcc -Wno-sign-compare
But you should really fix the comparison it's warning you about anyway.

robert
- 33,242
- 8
- 53
- 74
-
3However, some style guides (Google's, for example), suggest to not use unsigned types. http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Integer_Types – Feb 10 '11 at 04:16
-
@Sancho what about when dealing with `std` container indices/sizes? – robert Feb 10 '11 at 14:23
-
A strict reading of that style guide (I know, style guides aren't meant to be strict) would suggest that even in that case, unsigned integers are discouraged. I'm not clear about the full rationale behind that. My main point was that there could be situations where suppressing the warning is more desired than fixing the warning. – Feb 10 '11 at 22:04
-
7Just want to say that this was a good answer. First answered, then preached. It really boils in me when it is the other way around. – RushPL Jun 28 '14 at 14:41
-
@robert, there are good reasons why you **don't** want to fix the issue from time to time. For example, finding in a string and comparing to std::string::npos. If you use an unsigned integer, you will never have a true comparison, but otherwise, you get a compiler warning. – Alex Huszagh Jul 05 '16 at 16:55
-
3@AlexanderHuszagh `std::string::find` returns a `std::string::size_type`, which is coincidentally the type of `std::string::npos`. I've never had any problem comparing a `std::string::size_type` with another `std::string::size_type`. – robert Jul 07 '16 at 10:50
-
@robert Thanks for correcting my assertive and completely inaccurate statement (like actually). – Alex Huszagh Jul 07 '16 at 14:07
-
4In my opinion, Google's style guide has many controversial points, this one being one of them. – lisyarus Jul 25 '16 at 07:29
-
It's almost never worth adding casts to fix this, and it's even less worth using unsigned--that can cause much bigger headaches when you subtract 1 and end up with 18446744073709551615 instead of -1. This is just a misguided warning that should always be disabled. – Glenn Maynard Aug 19 '16 at 03:38
-
@Robert Would be nice to fix it, but in some situations (such as mine right now) I'm dealing with massive legacy code where signed and unsigned integers from different systems must be compared, as refactoring was deemed far too costly. Very unfortunately in my current case, if our indices get high enough (unlikely, but possible since the system gets left on months/years at a time), we could end up with one system's valid id's being viewed as invalid in the other system, and records will get dropped in that case. D: But I don't have permission to fix, yet I'm ordered to have 0 warnings. – Loduwijk Nov 09 '16 at 17:05
6
Here's what worked for me, using the gcc compiler in Code::Blocks. In the compiler settings, click the "Compiler Settings" tab, then choose "Other Compiler Options. Type in -Wno-sign-compare The warning -Wsign-compare can be negated by adding "-Wno" as a prefix. In fact warnings can be ignored by adding -Wno- to the warning code.

the_architect
- 69
- 1
- 2