为什么锵警告:''和;&放大器;'内部'||'`? [英] Why does Clang warn: `'&&' within '||'`?

查看:504
本文介绍了为什么锵警告:''和;&放大器;'内部'||'`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的理解是括号没有什么区别,因此没有任何理由认为锵提醒这是一个默认值(不是改善code-清晰度等)?我preFER不添加,因为我不喜欢加入code为code的缘故括号。

 的src / websocket.c:420:43:警告:'和;&放大器;'内部'||' [-Wlogical-OP-括号]
        如果(RV == 0安培;&安培; N = 0 || RV == -1放大器;!&放大器;错误号== ECONNRESET){
                              ~~ ^ ~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~
SRC / websocket.c:420:43:注意:周围的地方括号'和;&放大器;'前pression到
      关闭此警告
        如果(RV == 0安培;&安培; N = 0 || RV == -1放大器;!&放大器;错误号== ECONNRESET){
                                 ~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~


解决方案

的自然倾向是读它从左到右,而且很容易忘记操作precedence。这就是说,它只是一个警告,如果你知道你在做什么,你自己的风格允许,随意燮preSS它。

My understanding is the parentheses make no difference, so is there any reason (other than to "improve" code-clarity) that Clang warns this as a default? I prefer not to add the parentheses as I dislike adding code for code’s sake.

src/websocket.c:420:43: warning: '&&' within '||' [-Wlogical-op-parentheses]
        if (rv == 0 && N != 0 || rv == -1 && errno == ECONNRESET) {
                              ~~ ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
src/websocket.c:420:43: note: place parentheses around the '&&' expression to
      silence this warning
        if (rv == 0 && N != 0 || rv == -1 && errno == ECONNRESET) {
                                 ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~

解决方案

The natural tendency is to read it left to right, and it's easy to forget the operator precedence. That said, it's just a warning, and if you know what you're doing and your own style allows it, feel free to suppress it.

这篇关于为什么锵警告:''和;&放大器;'内部'||'`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆