Article View: comp.lang.c++
Article #751Re: does an expression in a logical statement need parenthesis for proper evaluation?
From: Lawrence D’Oliveiro
Date: Fri, 06 Nov 2026 01:12
Date: Fri, 06 Nov 2026 01:12
31 lines
2395 bytes
2395 bytes
On Thu, 5 Nov 2026 19:52:31 -0500, James Kuyper wrote:
> For historical reasons, bitwise or (|) and bitwise and (&) are
> exceptions. Unfortunately, correcting that mistake would break
> backwards compatibility ...
The only real issue is that bitwise ops have lower priority than
comparisons, when they should be higher. If they were higher, then an
expression like
(bitval & mask) == desired_value
wouldn’t need parentheses.
Realistically, can anyone offer *any* real-world C code that
uses an expression that would be parenthesized like
a & (b == c)
? The reason why I ask is that Python makes exactly this change to the
operator precedences, and I have yet to come across anybody complain
that they converted some expression from C to Python, and it came up
with the wrong answer because of this issue.
In fact, I only discovered for myself that Python did the precedence
differently because I mistakenly wrote some code without the usual
C-precedence-compatible parentheses
bitval & mask == desired_value
and got the right answer anyway. ;)
Technical Details
Message-ID:
<11cj9he$24mi0$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<11cj4a0$23796$1@dont-email.me> <11cj8ch$24f93$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Lawrence D’Oliveiro <ldo@nz.invalid> Newsgroups: comp.lang.c++,comp.lang.c Subject: Re: does an expression in a logical statement need parenthesis for proper evaluation? Date: Fri, 6 Nov 2026 01:12:15 -0000 (UTC) Organization: A noiseless patient Spider Lines: 31 Message-ID: <11cj9he$24mi0$1@dont-email.me> References: <11cj4a0$23796$1@dont-email.me> <11cj8ch$24f93$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Fri, 06 Nov 2026 01:12:15 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2251328"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19UDLEXwZQLxmC3t1NYSqhK"; posting-host="805450eec5e4df4938c911987d9875f0" User-Agent: Pan/0.165 (Kostiantynivka) Cancel-Lock: sha1:bQIkAP5+2epSvHEC8IYD8aWzJkk= sha256:WszefMsrVEMntm3iXqFeAqoeZWzuVi37W1DrFl2ooxY= sha1:R7c+1mO9whO9y5Uub5ThyElOZkI= sha256:FuYDkFB12NgTbhYyPvNxtJPVtODxkWhQgHoj/izJ+zQ=