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

后端 未结 5 1428
说谎
说谎 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:59

    For gcc compiler you can add

    gcc -Wconversion ...
    

    And this will produce the following warning

    warning: converting negative value '-0x0000000000000000a' to 'unsigned int'
    

提交回复
热议问题