问题
so what is the difference between C4018 ('expression' : signed/unsigned mismatch) and C4389 ('operator' : signed/unsigned mismatch) warnings?
unsigned int uc = 0;
int c = 0;
if (uc < c) uc = 0; // C4018
vs
int a = 9;
unsigned int b = 10;
if (a == b) // C4389
I just don't get it.
回答1:
Biggest difference is the warning level at which these diagnostic messages are generated. C4018 is a level 3 warning. Falls in the "things you should not ignore" category. Just try the code you have with uc = 1 and c = -1 and ponder how 1 could possibly be less than -1. Just about no programmer expects that kind of outcome. That makes it a bug generator and deserves a visible diagnostic.
C4389 is a level 4 warning. Falls in the "looks wrong but probably works anyway" category. The signed-ness of the operands doesn't affect an equality comparison.
The default warning level is 3, unless you changed the project setting. That makes you see the "should not ignore" diagnostic and not the "probably works anyway" diagnostic.
来源:https://stackoverflow.com/questions/39479163/what-is-the-difference-between-warnings-c4018-expression-signed-unsigned-mi