Compiler warnings

Suppose I have this code (C ++ or possibly C):

vector<int> my_vector;
for (int i = 0; i < my_vector.size(); i++) {
    my_vector[i] = 0;
}

I don’t care if this is done correctly. The important part is in the for-loop declaration. The compiler gives a signature mismatch / unsigned for this, since size () returns an unsigned int, not a signed one. How important is changing ito unsigned? I declare cycle counts as ints out of habit, but if this is a potential mistake, I forced myself to break the habit.

+3
source share
6 answers

, - . , , , , .

, , - 32- 2 , unsigned . , , , , , / .

+10

, i vector<int>::size_type. typedef :

typedef vector<int> VectorType;
VectorType my_vector;
for (VectorType::size_type i = 0; i < my_vector.size(); i++) {
    my_vector[i] = 0;
}

, deque, . - , size_type, , , . . /, / , , .

+13

, INT_MAX. , int, .

+6

, , , , , , (), .

11111111 < 10000000

+1

. , , ( ), - , , .

, .

0

, vector:: size_type; . .

0

Source: https://habr.com/ru/post/1711513/


All Articles