<分区>
这是 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)) {
^
( )