🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c++
Article #745

Re: does an expression in a logical statement need parenthesis for proper evaluation?

#745
From: Keith Thompson
Date: Fri, 06 Nov 2026 00:33
25 lines
1897 bytes
Lynn McGuire <lynnmcguire5@gmail.com> writes:
> 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;
> }

No, but redundant parentheses are mostly harmless.

The outer parentheses are of course part of the syntax of the "if"
statement, but the operator precedences are unambiguous.  `j1 * i1 < 1`
can never be evaluated as `j1 * (i1 < 1)`.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
Technical Details
Message-ID: <11cj78g$244gp$1@kst.eternal-september.org>
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!kst.eternal-september.org!.POSTED!not-for-mail
References: <11cj4a0$23796$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!kst.eternal-september.org!.POSTED!not-for-mail
From: Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups: comp.lang.c++,comp.lang.c
Subject: Re: does an expression in a logical statement need parenthesis for proper evaluation?
Date: Thu, 05 Nov 2026 16:33:18 -0800
Organization: None to speak of
Lines: 25
Message-ID: <11cj78g$244gp$1@kst.eternal-september.org>
References: <11cj4a0$23796$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Fri, 06 Nov 2026 00:33:21 +0000 (UTC)
Injection-Info: kst.eternal-september.org;
	logging-data="2232857"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+xEcg5fe3HMkBAzqmMyDuR"; posting-host="470bea5a7c525a052be348861b0f0884"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:OnsfKZFtGqt+13LI7qZrEzQK0mM= sha256:sg+SGZA5c5BB/63M+xz2wCuCNFfEUWgdyleh/m0j1jA=
	sha1:qkcOKKazbv/q6SQ4asp9iWHn3ak= sha256:tsUU3tPboif/erGJxyEAlSGMZVP6UZ6bPTzKXQSWAMg=