警告 C4018('expression':signed/unsigned 不匹配)和 C4389('operator':signed/unsigned 不匹配)之间有什么区别
what is the difference between warnings C4018 ('expression' : signed/unsigned mismatch) and C4389 ('operator' : signed/unsigned mismatch)
那么 C4018 ('expression' : signed/unsigned mismatch) and C4389 ('operator' : signed/unsigned mismatch) 警告有什么区别?
unsigned int uc = 0;
int c = 0;
if (uc < c) uc = 0; // C4018
对
int a = 9;
unsigned int b = 10;
if (a == b) // C4389
我就是不明白。
最大的区别是生成这些诊断消息的警告级别。 C4018 是 3 级警告。属于 "things you should not ignore" 类别。只需尝试使用 uc = 1 和 c = -1 的代码,并思考 1 怎么可能小于 -1。几乎没有程序员期望这样的结果。这使它成为一个错误生成器,值得一个可见的诊断。
C4389 为 4 级警告。属于 "looks wrong but probably works anyway" 类别。操作数的符号性不影响相等比较。
默认警告级别为 3,除非您更改了项目设置。这使您看到 "should not ignore" 诊断而不是 "probably works anyway" 诊断。
那么 C4018 ('expression' : signed/unsigned mismatch) and C4389 ('operator' : signed/unsigned mismatch) 警告有什么区别?
unsigned int uc = 0;
int c = 0;
if (uc < c) uc = 0; // C4018
对
int a = 9;
unsigned int b = 10;
if (a == b) // C4389
我就是不明白。
最大的区别是生成这些诊断消息的警告级别。 C4018 是 3 级警告。属于 "things you should not ignore" 类别。只需尝试使用 uc = 1 和 c = -1 的代码,并思考 1 怎么可能小于 -1。几乎没有程序员期望这样的结果。这使它成为一个错误生成器,值得一个可见的诊断。
C4389 为 4 级警告。属于 "looks wrong but probably works anyway" 类别。操作数的符号性不影响相等比较。
默认警告级别为 3,除非您更改了项目设置。这使您看到 "should not ignore" 诊断而不是 "probably works anyway" 诊断。