Type conversion warning after bitwise operations in C

后端 未结 4 1166
傲寒
傲寒 2021-02-20 05:29

How do you explain that line 7 gets a warning, but not line 5 or line 6?

int main()
{
    unsigned char a = 0xFF;
    unsig         


        
4条回答
  •  花落未央
    2021-02-20 06:05

    I think the problem is that you convert int to unsigned char, AND back to int.

    Line 6 converts int to unsigned char, but just stores it into unsigned char.
    Line 7 converts int to unsigned char, and then, in order to do arithmetic, converts it back to int. The new integer may be different from the original, so you get a warning.

提交回复
热议问题