Why compiler is not giving error when signed value is assigned to unsigned integer? - C++

后端 未结 5 1454
说谎
说谎 2020-12-16 12:09

I know unsigned int can\'t hold negative values. But the following code compiles without any errors/warnings.

unsigned int a = -10;
<
5条回答
  •  一生所求
    2020-12-16 12:50

    I am using g++ 4.9.2 and need to use -Wsign-conversion to make this warning appear.

    gcc.gnu.org: Warnings about conversions between signed and unsigned integers are disabled by default in C++ unless -Wsign-conversion is explicitly enabled.

提交回复
热议问题