Article View: comp.lang.c++
Article #768Re: does an expression in a logical statement need parenthesis for proper evaluation?
From: Chris M. Thomasson
Date: Fri, 06 Nov 2026 21:29
Date: Fri, 06 Nov 2026 21:29
72 lines
3820 bytes
3820 bytes
On 11/6/2026 10:50 AM, 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)
^^^^^^^^^^^^^^^^^
Why? Is that a syntax error? Afaict, the count of open and close
parentheses do not match...
>
> 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.
>
> [...]
>
Technical Details
Message-ID:
<11clgrq$2tjgu$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> <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: "Chris M. Thomasson" <chris.m.thomasson.1@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 13:29:27 -0800 Organization: A noiseless patient Spider Lines: 72 Message-ID: <11clgrq$2tjgu$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:29:30 +0000 (UTC) Injection-Info: dont-email.me; logging-data="3067422"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX199jFYzs9Mi3ufzLzWD5FoYFUCuSQNxmws="; posting-host="05131b9d92d665448b45480425c57f0b" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:1uIYpOgbyWI0wBr2KHG/DwLqpKY= sha256:Kl9CFhmX/prR6sapgRMp5+XFppG+13flx8fbGyrmYPk= sha1:A96LStoSz5kocKwq7FrIXfPos3A= sha256:BRwytuK5Eyb1T1ZI0v7gX5xeR+Wm/2F1/pvbXqqf4Do= Content-Language: en-US In-Reply-To: <11cl7i3$2pbh3$1@kst.eternal-september.org>