g ++ -Wsign-compare int vs short

时间:2017-12-12 13:43:47

标签: c++ comparison unsigned signed short

我们来看下面的C ++示例代码:

int main() {
    int a = 0;
    unsigned int b = 1;
    if (a < b) {
        // do stuff
    }
}

这是用

编译的
g++ -Wall -O0

并发出警告

warning: comparison between signed and unsigned integer expressions

正如所料。

如果我将a和b的类型更改为short和unsigned short,编译器警告就会消失。为什么呢?

0 个答案:

没有答案