My understanding is the parentheses make no difference, so is there any reason (other than to “improve“ code-clarity) that Clang warns this as a default? I prefer not to add the parentheses as I dislike adding code for code’s sake.
src/websocket.c:420:43: warning: '&&' within '||' [-Wlogical-op-parentheses]
if (rv == 0 && N != 0 || rv == -1 && errno == ECONNRESET) {
~~ ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
src/websocket.c:420:43: note: place parentheses around the '&&' expression to
silence this warning
if (rv == 0 && N != 0 || rv == -1 && errno == ECONNRESET) {
~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
(GNU C is a language, GCC is a compiler for that language.Clang defines __GNUC__ / __GNUC_MINOR__ / __GNUC_PATCHLEVEL__ according to the version of gcc that it claims full compatibility with.
Clang is designed to provide a frontend compiler that can replace GCC. Apple Inc. (including NeXT later) has been using GCC as the official compiler. GCC has always performed well as a standard compiler in the open source community.
Clang is much faster and uses far less memory than GCC. Clang aims to provide extremely clear and concise diagnostics (error and warning messages), and includes support for expressive diagnostics. GCC's warnings are sometimes acceptable, but are often confusing and it does not support expressive diagnostics.
The natural tendency is to read it left to right, and it's easy to forget the operator precedence. That said, it's just a warning, and if you know what you're doing and your own style allows it, feel free to suppress it.
I'm guessing because it's simply a bit unclear, unless the reader is very good at C's operator precedence rules.
Your expression is like this:
if (A && B || C && D)
and since &&
has higher precendence than ||
, it means
if ((A && B) || (C && D))
which I guess is what you mean, but it's not very clear when reading.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With