Often an object I use will have (signed) int
parameters (e.g. int iSize
) which eventually store how large something should be. At the same time, I will often initialize them to -1
to signify that the object (etc) hasn't been setup / hasn't been filled / isn't ready for use.
I often end up with the warning comparison between signed and unsigned integer
, when I do something like if( iSize >= someVector.size() ) { ... }
.
Thus, I nominally don't want to be using an unsigned int
. Are there any situations where this will lead to an error or unexpected behavior?
If not: what is the best way to handle this? If I use the compiler flag -Wno-sign-compare
I could (hypothetically) miss a situation in which I should be using an unsigned int
(or something like that). So should I just use a cast when comparing with an unsigned int
--e.g. if( iSize >= (int)someVector.size() ) { ... }
?