Issue
The following line gives me a warning:
for (int i = 0; i < SpamBannListArray.size(); i++)
char.cpp: In member function 'bool CHARACTER::SpamListCheck(const char*)': char.cpp:7280: warning: comparison between signed and unsigned integer expressions
What do I need to change in order to get rid of the warning above?
Solution
You should use a unsigned
type for the declaration of i
in the for()
loop header, since SpamBannListArray.size()
most probably returns an unsigned
type:
for (unsigned int i = 0; i < SpamBannListArray.size(); i++)
// ^^^^^^^^
or
for (size_t i = 0; i < SpamBannListArray.size(); i++)
Otherwise your code might be prone for signed
value overflows / wraparounds when hitting negative values.
As pointed out in comments using a range based for()
loop, without need to specify an indexing variable should be preferred with the current c++ standard:
for (auto item : SpamBannListArray) {
// Do something with item
}
In case you need to manipulate items inplace, use auto &
.
Answered By - πάντα ῥεῖ Answer Checked By - David Marino (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.