🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

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

#762
From: Keith Thompson
Date: Fri, 06 Nov 2026 18:50
68 lines
3568 bytes
David Brown <david.brown@hesbynett.no> writes:
> On 06/11/2026 02:07, Lynn McGuire wrote:
>> On 11/5/2026 5:42 PM, Lynn McGuire wrote:
>>> Hi,
>>>
>>> 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;
>>> }
>>>
>>> Thanks,
>>> Lynn
>> Thank you all very much.  BTW, there were parenthesis in the old
>> Fortran code but F2C stripped them out.  I put them back in for my
>> comfort as I see them.
>> 
>
> Since you are generating the C++ code automatically, there should not
> be a problem adding the parentheses.  Generated code that contains
> "goto L463" is clearly not intended for humans anyway (at least, not
> without a good deal of effort).

My understanding is that the C++ code being generated is intended to be
maintained as C++ code.  Lynn can confirm or deny that.  He's using f2c
and a lot of manual cleanup.

In this particular example:

    if ((j1 * i1) < 1)

I find the inner parentheses slightly distracting.  I'd wouldn't
write it that way myself, but it wouldn't particularly bother me
if I saw it in someone else's code, and I likely wouldn't mention
it unless asked.

If this were my project, as long as I'm having to do substantial
manual cleanup, I'd probably change it to:

    if (j1 * i1) < 1)

In a quick test, f2c didn't add parentheses given a Fortran input of
"if (j1 * i1 < 1)".  Either the inner parentheses were there in the
Fortran code, or something else is going on.
    
> There is a proportion of programmers who think it is somehow blasphemy
> to use more parentheses in an expression than strictly necessary.
> That type of programmer will also disapprove of the extra braces
> around the "goto" in your example.

Small quibble: The extra parentheses were in the condition in an "if"
statement, not a goto.  Parentheses in a "goto" statement would be a
syntax error.

[...]

-- 
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: <11cl7i3$2pbh3$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> <11cj994$24m06$1@dont-email.me> <11ck0pr$2amtc$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: Fri, 06 Nov 2026 10:50:41 -0800
Organization: None to speak of
Lines: 68
Message-ID: <11cl7i3$2pbh3$1@kst.eternal-september.org>
References: <11cj4a0$23796$1@dont-email.me> <11cj994$24m06$1@dont-email.me>
	<11ck0pr$2amtc$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 18:50:44 +0000 (UTC)
Injection-Info: kst.eternal-september.org;
	logging-data="2928163"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+P1CKgfINlA6jnbEI4nK7T"; posting-host="470bea5a7c525a052be348861b0f0884"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:PRWuP/UTldVOnTkHnK2vmTmCtSg= sha256:kok93fSgrCloqJCqmNQBoR6MmaeVIOOKbcPolTE2f88=
	sha1:YLH/DiN5XFkIrqyjW72CTfPf7XE= sha256:YOJP5FvuentqWb3aWm199XJmhlO0u6de4rscKHRs42I=