Article View: comp.lang.c
Article #1391Re: does an expression in a logical statement need parenthesis for proper evaluation?
From: James Kuyper
Date: Mon, 09 Nov 2026 11:00
Date: Mon, 09 Nov 2026 11:00
34 lines
2759 bytes
2759 bytes
On 2026-11-09 02:32, Andrey Tarasevich wrote:
> On Thu 11/5/2026 3:42 PM, Lynn McGuire wrote:
>> Does an expression in a logical statement need parenthesis for proper
>> evaluation in C and/or C++?
>>
>> In other words, should
>>
>> if (j1 * i1 < 1) {
>> goto L463;
>> }
>>
>> be
>>
>> if ((j1 * i1) < 1) {
>> goto L463;
>> }
>>
> The whole `j1 * i1 < 1` is an expression in this case. It is parsed in
> accordance with the grammar, which ultimately makes it equivalent to
> `(j1 * i1) < 1`.
>
> Your question seems to suggest that the `j1 * i1` part somehow qualifies
> as an expression, while the rest of it does not. That's not how it
> works. The language does not give the `j1 * i1` part any special status.
You are correct, parentheses are not needed. However, there's a related
question that could have a different answer: should an arithmetic
expression that is an operand of a comparison expression be
parenthesized - not because it needs the parenthesis, but to clarify
what the grammar already guarantees?
I tend not to use unnecessary parentheses, and I know the grammar well
enough to correctly identify them - but many people don't know the
grammar that well, which might include the next person to maintain my
code. There are reasonable arguments that I should use parentheses more
than I actually do, for the benefit of such people.
Technical Details
Message-ID:
<11cs94q$15ptp$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> <11crsub$11ikc$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: James Kuyper <jameskuyper@alumni.caltech.edu> Newsgroups: comp.lang.c++,comp.lang.c Subject: Re: does an expression in a logical statement need parenthesis for proper evaluation? Date: Mon, 9 Nov 2026 06:00:40 -0500 Organization: A noiseless patient Spider Lines: 34 Message-ID: <11cs94q$15ptp$1@dont-email.me> References: <11cj4a0$23796$1@dont-email.me> <11crsub$11ikc$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Mon, 09 Nov 2026 11:00:43 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1238969"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Uc8v4zZxGWb+0/342y8/7CzcxrFvKtBc="; posting-host="ae635dcf03c03971c9d3802a544f3d65" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:AIolfESAadkJVlbQPFEeBjF8bng= sha256:BY8c4e5PKumtwxebmE65osZ0X/85J664gvMtKsM/f8Q= sha1:CAX6A60HVL83GK85ixwgx286Ov4= sha256:L35n5N5BHN7n32AFJpqYHYkfTtWy+vsWoNagV74MtOM= In-Reply-To: <11crsub$11ikc$1@dont-email.me> Content-Language: en-US