“token”:有符号/无符号不匹配
注解
使用 token 运算符比较 和 signed 数字需要编译器将 unsigned 值转换为 signedunsigned。
解决此警告的一种方法是在比较 signed 和 unsigned 类型时强制转换这两种类型中的一种。
示例
此示例生成 C4018 并演示如何修复:
// C4018.cpp
// compile with: cl /EHsc /W4 C4018.cpp
int main() {
unsigned int uc = 0;
int c = 0;
unsigned int c2 = c; // implicit conversion
if (uc < c) // C4018
uc = 0;
if (uc < unsigned(c)) // OK
uc = 0;
if (uc < c2) // Also OK
uc = 0;
}