Signed/unsigned comparisons

后端 未结 5 792
情歌与酒
情歌与酒 2020-11-22 06:29

I\'m trying to understand why the following code doesn\'t issue a warning at the indicated place.

//from limits.h
#define UINT_MAX 0xffffffff /* maximum unsi         


        
5条回答
  •  囚心锁ツ
    2020-11-22 07:19

    The == operator just does a bitwise comparison (by simple division to see if it is 0).

    The smaller/bigger than comparisons rely much more on the sign of the number.

    4 bit Example:

    1111 = 15 ? or -1 ?

    so if you have 1111 < 0001 ... it's ambiguous...

    but if you have 1111 == 1111 ... It's the same thing although you didn't mean it to be.

提交回复
热议问题