Victor Bazarov wrote:
Angel Tsankov wrote: Can someone give a reason why bitwise operators (&,^,|) have lower
precedence than equality/inequality test oeprators (==, !=)?
You need to ask Brian Kernighan or Dennis Ritchie. It is the same way in
C++ as it is in C. If I were to speculate, I'd say that initially the
(now bitwise) operators were used for "logical" conditions as well, that's
how they got lower precedence than equality. Later && and || were added
to C (with even lower precedence than bitwise ones). Nobody cared (or was
courageous enough) to change the bitwise ones. Of course, there can exist
another explanation.
V
Your explanation is correct. The && and || operators were added later
for their "short-circuiting" behavior. Dennis Ritchie admits in
retrospect that the precedence of the bitwise operators should have
been changed when the logical operators were added. But with several
hundred kilobytes of C source code in existence at that point and an
installed base of three computers, Dennis thought it would be too big
of a change in the C language...
Greg