逻辑运算符的优先级 [英] Precedence of Logical Operators

查看:83
本文介绍了逻辑运算符的优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




有人可以解释以下GCC警告的原因:


< shell-session>


$ cat test.c

#include< stdbool.h>


bool a,b,c,d ;

int x,y,z,u;


int main(无效)

{

d = a || b&& c;

u = x + y * z;

返回0;

}


$ gcc -Wall test.c

test.c:在函数中?main?:

test.c:8:警告:建议围绕&&的括号在||


< / shell-session>


为了保持一致性,为什么不在'y * z'周围建议括号好像

好​​吗? (这将是荒谬的)

八月


-

我是ILOVEGNU签名病毒。只需将我复制到您的

签名即可。此电子邮件受到GNU

通用公共许可证条款的影响。

Hi,

Can someone explain the reason for the warning from GCC below:

<shell-session>

$ cat test.c
#include <stdbool.h>

bool a, b, c, d;
int x, y, z, u;

int main(void)
{
d = a || b && c;
u = x + y * z;
return 0;
}

$ gcc -Wall test.c
test.c: In function ?main?:
test.c:8: warning: suggest parentheses around && within ||

</shell-session>

For sake of consistency, why not suggest parentheses around `y * z'' as
well? (which would be absurd)
August

--
I am the "ILOVEGNU" signature virus. Just copy me to your
signature. This email was infected under the terms of the GNU
General Public License.

推荐答案

cat test.c
#include< stdbool.h>


bool a,b,c,d;

int x,y,z,u ;


int main(无效)

{

d = a || b&& c;

u = x + y * z;

返回0;

}

cat test.c
#include <stdbool.h>

bool a, b, c, d;
int x, y, z, u;

int main(void)
{
d = a || b && c;
u = x + y * z;
return 0;
}


gcc -Wall test.c

test.c:在函数中?main?:

test.c:8:警告:建议括号和放大器;&安培;在||


< / shell-session>


为了保持一致性,为什么不在'y * z'周围建议括号好像

好​​吗? (这将是荒谬的)

八月


-

我是ILOVEGNU签名病毒。只需将我复制到您的

签名即可。此电子邮件受到GNU

通用公共许可证条款的影响。
gcc -Wall test.c
test.c: In function ?main?:
test.c:8: warning: suggest parentheses around && within ||

</shell-session>

For sake of consistency, why not suggest parentheses around `y * z'' as
well? (which would be absurd)
August

--
I am the "ILOVEGNU" signature virus. Just copy me to your
signature. This email was infected under the terms of the GNU
General Public License.


2005-11-20,August Karlstrom< fu * *******@comhem.se>写道:
On 2005-11-20, August Karlstrom <fu********@comhem.se> wrote:


有人可以解释以下GCC警告的原因:

Hi,

Can someone explain the reason for the warning from GCC below:


这篇关于逻辑运算符的优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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