In general, I want warnings of unsigned vs signed.
However, in this particular case, I want it suppressed;
std::vector<Blah> blahs;
for(int i = 0; i < blahs.size(); ++i) { ...
I want to kill this comparison.
Thanks!
(using g++)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should fix, not suppress. Use an unsigned type:
You can also use
unsigned, butsize_tis more appropriate here (and may have a different, larger, range). If you’re only usingito iterate and don’t need its value in the loop, use iterators instead:If your compiler does not support
auto, replaceautowithT::iteratororT::const_iterator, whereTis the type ofblahs. If your compiler supports a fuller subset of C++11, though, do this:Which is best of all.
Strictly speaking, the above is not “correct”. It should be:
But this can be verbose, and every implementation I know uses
size_tassize_typeanyway.If for some reason you really need a signed integer type for
i, you’ll have to cast: