I'm trying to switch from Turbo C++ to MSVC++, I've gotten most of the differences in coding and libraries worked out, though I keep getting this problem and I have tried to find a solution but I haven't been able to find one after 30 minutes of searching for it. I have various line of codes where I have for(I=0;I<Item.size();++I) , and in every single line I have that it gives me the warning.

warning C4018: '<' : signed/unsigned mismatch

Though since it is only a warning, it runs fine, but am I doing something wrong or do you do it a different way in Visual C++?

10 Years
Discussion Span
Last Post by vijayan121

You must have declared I as an integer variable while size() returns a number of type unsigned integer. Hence the warning message. Try changing the loop variable to type size_t and it should work out to be fine.

Read this.


comparing a signed value with an unsigned
value has a logical problem.

int si = -7 ;
unsigned int ui = 68 ;
( si < ui ) ; 
// true if interpreted as si < signed(ui)
// false if interpreted as unsigned(si) < ui

at the very least, the behavoiur is
'implementation dependant'

however, if the signed value is >= 0, and
the unsigned value is less than half of the
possible max value for the type, there
would be no differences between

Votes + Comments
Makes sense and helpful
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.