🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #1220

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

#1220
From: Lynn McGuire
Date: Fri, 06 Nov 2026 21:27
82 lines
4338 bytes
On 11/6/2026 12:50 PM, 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.
> 
> 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.
> 
> [...]

Yup, I am moving to C++ totally.  Actually, a very mild version of C++ 
for my 850,000 line calculation engine.  No classes, all character 
strings in std::string variables, and a few other things.  The old 
Fortran code was not type safe at all, the new C++ code is trying to use 
type safety everywhere.

One of my worst experiences with Smalltalk was a crash in the software 
going to an error message with a crash in the error message due to a 
missing method in the Smalltalk class.  We had happen way too often.

Yes, I am using a heavily modified version of F2c and way too much 
manual cleanup.  I need to modify F2C some more but probably will not as 
I am 40 or 45% code complete now.

Lynn
Technical Details
Message-ID: <11clgoj$2tiij$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-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: Lynn McGuire <lynnmcguire5@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, 6 Nov 2026 15:27:44 -0600
Organization: A noiseless patient Spider
Lines: 82
Message-ID: <11clgoj$2tiij$1@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: Fri, 06 Nov 2026 21:27:47 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="3066451"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18eclCV4sHl8neMOdv/on3FkT5RPJsHQ/A="; posting-host="9424d41671042b4b3ea15a90032ad150"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:BKgTk1A3Ul8EtBSxCJgjyJDGEM8= sha256:6RZFpSnA/wOwb2Twxynnr+oRDHF1pxGv7+DzL1gUsW8=
	sha1:wQtlZsxBXn5PK2K8scyjyTDJRq4= sha256:utgiCosKMrO/9f1mdNIGknhWnDTg5Lgnv1T63hqGxnQ=
Content-Language: en-US
In-Reply-To: <11cl7i3$2pbh3$1@kst.eternal-september.org>