操作precedence(按位'和,'低于'==') [英] Operator precedence (bitwise '&' lower than '==')

查看:132
本文介绍了操作precedence(按位'和,'低于'==')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C编程语言,为什么按位运算符(安培;以及|)具有较低的precedence比等号(= =)?这是没有道理给我。

In the C programing language, why do the bitwise operators (& and |) have lower precedence than the equality operator (==)? It does not make sense to me.

推荐答案

您要问布赖恩Kernighan的或丹尼斯里奇。结果
从这个论坛:<一href=\"http://bytes.com/topic/c/answers/167377-operator-$p$pcedence\">http://bytes.com/topic/c/answers/167377-operator-$p$pcedence

You need to ask Brian Kernighan or Dennis Ritchie.
From this forum: http://bytes.com/topic/c/answers/167377-operator-precedence

&将功放;&安培;和||运营商是后来添加
      他们的短路的行为。丹尼斯里奇承认在
      回想起来,该位运算符的precedence应该有
      当加入的逻辑运算符被更改。但是,有几个
      几百KB的C源$ C ​​$ C的存在在这一点上和
      三台电脑安装基础,丹尼斯认为这将是太大
      在C语言中的改变...

The && and || operators were added later for their "short-circuiting" behavior. Dennis Ritchie admits in retrospect that the precedence of the bitwise operators should have been changed when the logical operators were added. But with several hundred kilobytes of C source code in existence at that point and an installed base of three computers, Dennis thought it would be too big of a change in the C language...

所以,这可能是一个原因?我猜,因为有按位precendence几层(不像关系比较),这是因为这是克鲁夫特存在...永远...,只是从来没有纠正。

So, that might be a reason? I'm guessing since there are several layers of bitwise precendence (unlike relational comparisons) that it's cruft that's existed since...forever...and just was never corrected.

这篇关于操作precedence(按位'和,'低于'==')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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