Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22031

gcc -Wparentheses warns for b=1; !a & b but not !a & 1

$
0
0

Consider following short program:

int main() {
    int a = 5, b = 1, c;
    c = !a & b;
    c = !a & 1;

    return c;
}

Does anyone know why gcc gives a warning for c = !a & b; but not for c = !a & 1;?

$gcc -Wall test.c
test.c: In function 'main':
test.c:3:9: warning: suggest parentheses around operand of '!' or change '&' to '&&' or '!' to '~' [-Wparentheses]
     c = !a & b;

My gcc version is 8.3.1 (I tried with one other version and the same thing happens).

I'm often surprised how 'smart' gcc is. And this one looks like a very easy problem to figure out. So why still a warning for the first one?


Viewing all articles
Browse latest Browse all 22031

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>