🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

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

#783
From: David Brown
Date: Sat, 07 Nov 2026 11:48
99 lines
4600 bytes
On 06/11/2026 19:50, Keith Thompson wrote:
> 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.
> 

Okay.  If that is the case, however, I'd worry more about the "goto 
L463" than an extra set of parentheses.

My impression is that he is still fiddling with his fork of f2c with an 
aim to getting as much automation as he can to minimise the manual 
cleanup, but I could easily be wrong here.  I have no idea if it is 
possible to automate something to help with such gotos.

> 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)

I suspect you'd change it to something with balanced parentheses :-)

I personally would probably have the extra parentheses, but I would not 
be concerned about code that lacked it.

> 
> 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.
> 

I was talking about the extra braces, not extra parentheses - i.e.,

	if (j1 * i1 < 1) {
	    goto L463;
	}

vs.

	if (j1 * i1 < 1)
	    goto L463;


This is again a matter of style.  I guess Lynn's aim will be to have his 
version of f2c generate as good a match for the style he wants, to 
reduce the manual post-processing.



Technical Details
Message-ID: <11cn35u$3cl3b$2@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-mail
References: <11cj4a0$23796$1@dont-email.me> <11cj994$24m06$1@dont-email.me> <11ck0pr$2amtc$1@dont-email.me> <11cl7i3$2pbh3$1@kst.eternal-september.org>

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: David Brown <david.brown@hesbynett.no>
Newsgroups: comp.lang.c++,comp.lang.c
Subject: Re: does an expression in a logical statement need parenthesis for
 proper evaluation?
Date: Sat, 7 Nov 2026 12:48:14 +0100
Organization: A noiseless patient Spider
Lines: 99
Message-ID: <11cn35u$3cl3b$2@dont-email.me>
References: <11cj4a0$23796$1@dont-email.me> <11cj994$24m06$1@dont-email.me>
 <11ck0pr$2amtc$1@dont-email.me> <11cl7i3$2pbh3$1@kst.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 07 Nov 2026 11:48:15 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="3560555"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/nNvCwbj7PgrRRY8lWHsTZnr0SqOL/oPQ="; posting-host="f465dee2b09096cb458f10009f5504bd"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:zxMN5lkJOomLIUdNhUExdu3scUE= sha256:wq7uYTMqca/MKNcvg103j1nKkyQQuJXQX4L8A3EtlGg=
	sha1:wd0jEdGLeV+gvNXUHyAq2p+PGI8= sha256:mlP3Ev8oaF3+/RbTYsF6yFtn2lHeAtHbRhjLL0+Aa7M=
In-Reply-To: <11cl7i3$2pbh3$1@kst.eternal-september.org>
Content-Language: en-GB