Signed/unsigned comparisons

后端 未结 5 858
情歌与酒
情歌与酒 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:23

    In a system that represents the values using 2-complement (most modern processors) they are equal even in their binary form. This may be why compiler doesn't complain about a == b.

    And to me it's strange compiler doesn't warn you on a == ((int)b). I think it should give you an integer truncation warning or something.

提交回复
热议问题