Is comparing a BOOL against YES dangerous?

后端 未结 4 2097
轻奢々
轻奢々 2020-12-15 12:29

I found a comment today in a source file:

//  - no longer compare BOOL against YES (dangerous!)

Is comparing BOOL against

4条回答
  •  温柔的废话
    2020-12-15 12:59

    When the code uses a BOOL variable, it is supposed to use such variable as a boolean. The compiler doesn't check if a BOOL variable gets a different value, in the same way the compiler doesn't check if you initialize a variable passed to a method with a value taken between a set of constants.

提交回复
热议问题