How to silence a particular “pointless comparison of unsigned with zero” warning?

后端 未结 4 1455
無奈伤痛
無奈伤痛 2021-01-18 01:59

Suppose I have a function like the following:

#define LOWER_BOUND 0
#define UPPER_BOUND 42

int is_value_in_range( some_typedef val)
{
    return ((LOWER_BOU         


        
4条回答
  •  借酒劲吻你
    2021-01-18 02:20

    Rather than trying to silence the warning, why not do something about it and avoid the typedef in the first place? You can make overloads to handle specific cases and by avoiding the masking of warnings your more explicitly declaring that you're handling the cases you're dealing with. In my experience, that tends to force you to test new code instead of masking things which might happen in the future (like suddenly changing data types and then having to deal with values mysteriously failing to lie in expected ranges).

提交回复
热议问题