Why Is Comparing if an Unsigned Int >= 0 a “Pointless Comparison”?

后端 未结 10 1744
情话喂你
情话喂你 2021-02-12 10:44

I got warning:

Pe186 \"Pointless comparison of unsigned int with zero\"

when I tried to compile the following code:



        
10条回答
  •  [愿得一人]
    2021-02-12 10:48

    clLoop >= 0 is always true. It doesn't matter whether you pre-decrement or post-decrement, an unsigned value is at least 0. When you decrement 0 you get UINT_MAX.

    The compiler figures that you probably don't mean to loop forever (or you'd have used a different construct, that more obviously loops forever), hence the warning.

提交回复
热议问题