I have written some code for detecting the Strongly Connected Components. It runs fine, but for one warning:
warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
I understand it is for the following notorious code snippet (as pointed out in this SO answer):
int i; //instead of size_t i;
vector< int > sorted;
...
for(i=sorted.size()-1; i>=0; --i) {
...
}
But how do I get rid of this warning? If I write size_t i;
, then I get a segmentation fault (and a Time Limit Exceeded on online judges, for which the code is written). If I use int i;
then I get the above warning (with which I am uncomfortable, and so is my professor).
So, any work around?
Edit: The code works fine on declaring i
as an int
. There is no vector over (or under) flow. Also, I do understand why there is a segmentation fault. My question precisely is, how do I circumvent it (without any warning)?