Why doesn't GCC produce a warning when assigning a signed literal to an unsigned type?

前端 未结 3 996
栀梦
栀梦 2021-01-04 04:53

Several questions on this website reveal pitfalls when mixing signed and unsigned types and most compilers seem to do a good job about generating warnings of this type. How

3条回答
  •  暖寄归人
    2021-01-04 05:14

    Using (unsigned)-1 is an often used way to set all bits and sometimes even quoted as reason for this (mis)feature of C, even by people who should know better . It's neither obvious nor portable -- the expression you want to use to set all bits is ~0 .

提交回复
热议问题