【发布时间】:2015-11-15 05:44:17
【问题描述】:
这是 GCC 的问题吗?我曾尝试在 Windows 上运行,但它不会引发此警告。有没有办法解决这个问题(除了插入括号)?
#include <stdio.h>
int x, y;
int main (void)
{
x = 3;
y = 7;
if ((y < 2) || (y > 5) && (x < 12)) {
printf ("Yes\n");
} else
printf ("Nope\n");
return 0;
}
结果:
/Users/filename:18:28: warning: '&&' within '||' [-Wlogical-op-parentheses]
if ((y < 2) || (y > 5) && (x < 12)) {
~~ ~~~~~~~~^~~~~~~~~~~
/Users/filename:18:28: note: place parentheses around the '&&' expression to
silence this warning
if ((y < 2) || (y > 5) && (x < 12)) {
^
( )
【问题讨论】:
-
这是一个警告,而不是错误,
-
投票重新打开,因为 OP 明确询问除了插入括号外如何修复 GCC 上的警告,并且链接的问题是针对 Clang 的,并且建议那里的解决方案不适用于 GCC。