If I am testing a bit (and please don't tell me better ways to test a bit - I know there are), are the inner parens redundant here?
Code:if ((work->flagbyte & 0x80) ==0) { ... }
If I am testing a bit (and please don't tell me better ways to test a bit - I know there are), are the inner parens redundant here?
Code:if ((work->flagbyte & 0x80) ==0) { ... }
Mainframe assembler programmer by trade. C coder when I can.
Yes, needed. The Operator man page would have told you this!
The bitwise operator has a lower precedence than the equality operator.
Last edited by rstanley; 12-22-2023 at 03:45 PM.
Ah yes, I see this now. No man pages on the system I'm using! Not all development systems are *nix.
Thank you!
Mainframe assembler programmer by trade. C coder when I can.
Here's a good link for you: C Operator Precedence - cppreference.com
The cppreference website is obviously targeted at C++, but they have C pages for a huge set of relevant topics. Probably the only thing they are missing is the POSIX/Windows fundamental stuff which is arguably not language-related, but which informs the language so heavily that it's hard to not have.
I recommend adding cppreference to your library of bookmarks as a useful place to go to find important language and library trivia.
My C precedence cheat sheet, designed to be very small.
All operators in a category are the same precedence, except for Binary.
In the Binary category, operators lower down are lower, as are operators to the right of a semicolon.
It seems idiotic that & is below ==, but perhaps it was meant to be occasionally used as a non-short-circuiting version of &&?Code:Postfix (LtoR) x++ x-- f() a[] o.m p->m (type){list} Prefix (RtoL) ++x --x +x -x ! ~ *p &o (type) sizeof _Alignof Binary (LtoR) * / % ; + - << >> ; < > <= >= ; == != & ; ^ ; | ; && ; || Ternary (RtoL) a ? b : c Assign (RtoL) = += -= *= /= %= <<= >>= &= ^= |= Comma (LtoR) ,
A little inaccuracy saves tons of explanation. - H.H. Munro
> It seems idiotic that & is below ==, but perhaps it was meant to be occasionally used as a non-short-circuiting version of &&?
Way way back in the mists of time....
In B and BCPL (the precursors of C), & and | were short-circuit when using in a boolean context.
And then it got messy....
Chistory
Read the section "Neonatal C"
Also Dennis Ritchie on & | vs. ==
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.