Thread View: comp.lang.c++
158 messages
158 total messages
Page 1 of 4
Started by Lynn McGuire
Thu, 05 Nov 2026 23:42
Page 1 of 4 • 158 total messages
does an expression in a logical statement need parenthesis for proper evaluation?
Author: Lynn McGuire
Date: Thu, 05 Nov 2026 23:42
Date: Thu, 05 Nov 2026 23:42
20 lines
1479 bytes
1479 bytes
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
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Keith Thompson
Date: Fri, 06 Nov 2026 00:33
Date: Fri, 06 Nov 2026 00:33
25 lines
1897 bytes
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 */
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Janis Papanagnou
Date: Fri, 06 Nov 2026 00:40
Date: Fri, 06 Nov 2026 00:40
37 lines
2263 bytes
2263 bytes
On 2026-11-06 00:42, Lynn McGuire wrote:
> Hi,
>
> Does an expression in a logical statement need parenthesis for proper
> evaluation in C and/or C++?
No, below (assuming i1 and j1 are arithmetic types (and not used
as "camouflaged" booleans) there's no parenthesis necessary.
The necessity of parentheses depends on the operators used. In
"C" the multiplication has higher precedence than the comparison.
I suggest to get an Operator Precedence Table from the Net and
inspect it until you got familiar with the operator precedences.
Most precedences are anyway sensibly defined as you'd expect it.
But be careful when using bit-expressions with '&', '|', and '^'
especially if used together with the comparison operators.
Janis
>
> In other words, should
>
> if (j1 * i1 < 1) {
> Â Â Â goto L463;
> }
>
> be
>
> if ((j1 * i1) < 1) {
> Â Â Â goto L463;
> }
>
> Thanks,
> Lynn
>
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Lawrence D’Oliveiro
Date: Fri, 06 Nov 2026 00:44
Date: Fri, 06 Nov 2026 00:44
6 lines
1493 bytes
1493 bytes
On Thu, 5 Nov 2026 17:42:54 -0600, Lynn McGuire wrote: > Does an expression in a logical statement need parenthesis for proper > evaluation in C and/or C++? No <https://en.cppreference.com/c/language/operator_precedence>.
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: James Kuyper
Date: Fri, 06 Nov 2026 00:52
Date: Fri, 06 Nov 2026 00:52
39 lines
2879 bytes
2879 bytes
On 2026-11-05 18:42, 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;
> }
No general statement can be made about that issue. It depends entirely
upon the expression. The syntax rules of C (and the slightly different
grammar rules of C++) specify what order the parts of the logical
expression get evaluated in. If that happens to be the order that you
want, no parentheses are needed. Otherwise, one or more parentheses
might solve the problem.
For the most part, the grammar was fairly well designed for the purpose
of reducing the number of parentheses needed. For example, all
arithmetic operators have higher precedence than the comparison
operators, which in turn have higher priority than the logical
operators. That is why the parentheses you added above are unnecessary.
For historical reasons, bitwise or (|) and bitwise and (&) are
exceptions. Unfortunately, correcting that mistake would break backwards
compatibility, which is a fairly high priority with both the C and C++
committees.
It never hurts to insert parentheses to specify precisely the order of
evaluation that you want - except insofar as other people reading your
code who know that a given set of parentheses are unnecessary might
guess that you don't. If you don't want them to do that, take the time
to learn the grammar rules.
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Lynn McGuire
Date: Fri, 06 Nov 2026 01:07
Date: Fri, 06 Nov 2026 01:07
27 lines
1831 bytes
1831 bytes
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.
Lynn
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Lawrence D’Oliveiro
Date: Fri, 06 Nov 2026 01:12
Date: Fri, 06 Nov 2026 01:12
31 lines
2395 bytes
2395 bytes
On Thu, 5 Nov 2026 19:52:31 -0500, James Kuyper wrote:
> For historical reasons, bitwise or (|) and bitwise and (&) are
> exceptions. Unfortunately, correcting that mistake would break
> backwards compatibility ...
The only real issue is that bitwise ops have lower priority than
comparisons, when they should be higher. If they were higher, then an
expression like
(bitval & mask) == desired_value
wouldn’t need parentheses.
Realistically, can anyone offer *any* real-world C code that
uses an expression that would be parenthesized like
a & (b == c)
? The reason why I ask is that Python makes exactly this change to the
operator precedences, and I have yet to come across anybody complain
that they converted some expression from C to Python, and it came up
with the wrong answer because of this issue.
In fact, I only discovered for myself that Python did the precedence
differently because I mistakenly wrote some code without the usual
C-precedence-compatible parentheses
bitval & mask == desired_value
and got the right answer anyway. ;)
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Keith Thompson
Date: Fri, 06 Nov 2026 05:35
Date: Fri, 06 Nov 2026 05:35
11 lines
1661 bytes
1661 bytes
James Kuyper <jameskuyper@alumni.caltech.edu> writes:
[...]
> Otherwise, one or more parentheses
> might solve the problem.
Technically correct (the best kind of correct), but *two* or more
parentheses are even better.
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: David Brown
Date: Fri, 06 Nov 2026 07:49
Date: Fri, 06 Nov 2026 07:49
58 lines
3544 bytes
3544 bytes
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).
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.
There is a proportion of programmers who think you should /always/ use
parentheses to show the precedence of operators.
Most programmers, I think, are in the middle. Parentheses here can make
the expression clearer at a glance, but it is also obvious what it means
when not using extra parentheses. It is common to have parentheses in
situations where the operator precedence is not as well known, or may
differ between programming languages - mixing bitwise and logical
operators and equality operators are examples.
You can get a reasonable balance using gcc's warnings - these also have
the big advantage of making it easy to check! "-Wparentheses" (enabled
by -Wall) will catch, for example, "a < b == c" which parses as "a < (b
== c)". If "-Wparentheses" does not lead to complaints, then your
generated code is probably okay without the extra parentheses - but you
can still add them here if you prefer.
In general, I think you want your generated code to pass "gcc -O2 -Wall"
cleanly (or the clang equivalent, which is /not/ -Weverything!). You
may even aim for -Wextra.
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Janis Papanagnou
Date: Fri, 06 Nov 2026 08:17
Date: Fri, 06 Nov 2026 08:17
18 lines
2175 bytes
2175 bytes
On 2026-11-06 08:49, David Brown wrote: > [...] > > There is a proportion of programmers who think it is somehow blasphemy > to use more parentheses in an expression than strictly necessary. [...] "blasphemy", wow! - The exaggerations (despite being here, allegedly, softened by the word "somehow") seem to have become in vogue, lately. (Formerly I saw such argumentation paths prevalently in one specific poster's posts only. Communication style seems to be infectious. :-) Most (all?) professionals seem to prefer clearness as you do. Whatever it needs to obtain that; less parentheses or additional parentheses - depending on the expressions' complexity and context! - Largely still subjective anyway, but less of religious intensity, I'd say. Janis
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: David Brown
Date: Fri, 06 Nov 2026 09:50
Date: Fri, 06 Nov 2026 09:50
27 lines
2712 bytes
2712 bytes
On 06/11/2026 09:17, Janis Papanagnou wrote: > On 2026-11-06 08:49, David Brown wrote: >> [...] >> >> There is a proportion of programmers who think it is somehow blasphemy >> to use more parentheses in an expression than strictly necessary. [...] > > "blasphemy", wow! - The exaggerations (despite being here, allegedly, > softened by the word "somehow") seem to have become in vogue, lately. > (Formerly I saw such argumentation paths prevalently in one specific > poster's posts only. Communication style seems to be infectious. :-) I thought the term "blasphemy" was so obviously an exaggeration that it could not be taken realistically. I intended to point out that there are extreme views in both directions regarding additional parentheses that do not change the meaning of expressions in the C language. > > Most (all?) professionals seem to prefer clearness as you do. Whatever > it needs to obtain that; less parentheses or additional parentheses - > depending on the expressions' complexity and context! - Largely still > subjective anyway, but less of religious intensity, I'd say. > Some people do treat these things with a surprising intensity. But it is more common to pretend and tongue-in-check exaggerate their importance.
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: James Kuyper
Date: Fri, 06 Nov 2026 15:33
Date: Fri, 06 Nov 2026 15:33
9 lines
1799 bytes
1799 bytes
On 2026-11-06 00:35, Keith Thompson wrote: > James Kuyper <jameskuyper@alumni.caltech.edu> writes: > [...] >> Otherwise, one or more parentheses >> might solve the problem. > > Technically correct (the best kind of correct), but *two* or more > parentheses are even better. I should have said "... one or more matched pairs of parentheses ...".
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Scott Lurndal
Date: Fri, 06 Nov 2026 15:56
Date: Fri, 06 Nov 2026 15:56
23 lines
1911 bytes
1911 bytes
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes: >On 2026-11-06 00:42, Lynn McGuire wrote: >> Hi, >> >> Does an expression in a logical statement need parenthesis for proper >> evaluation in C and/or C++? > >No, below (assuming i1 and j1 are arithmetic types (and not used >as "camouflaged" booleans) there's no parenthesis necessary. > >The necessity of parentheses depends on the operators used. In >"C" the multiplication has higher precedence than the comparison. > >I suggest to get an Operator Precedence Table from the Net and >inspect it until you got familiar with the operator precedences. >Most precedences are anyway sensibly defined as you'd expect it. >But be careful when using bit-expressions with '&', '|', and '^' >especially if used together with the comparison operators. Lynn has been working on his "fortran" -> "C++" conversion for over a decade now. That he isn't familar with the C operator precedence table is rather frightening.
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Janis Papanagnou
Date: Fri, 06 Nov 2026 18:14
Date: Fri, 06 Nov 2026 18:14
11 lines
1714 bytes
1714 bytes
On 2026-11-06 16:56, Scott Lurndal wrote: >> [...] > > Lynn has been working on his "fortran" -> "C++" conversion > for over a decade now. That he isn't familar with the > C operator precedence table is rather frightening. Well, astonishing. - But let's help those who ask for help. :-) Janis
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Janis Papanagnou
Date: Fri, 06 Nov 2026 18:18
Date: Fri, 06 Nov 2026 18:18
25 lines
2457 bytes
2457 bytes
On 2026-11-06 10:50, David Brown wrote: > On 06/11/2026 09:17, Janis Papanagnou wrote: >> On 2026-11-06 08:49, David Brown wrote: >>> [...] >>> >>> There is a proportion of programmers who think it is somehow >>> blasphemy to use more parentheses in an expression than strictly >>> necessary. [...] >> >> "blasphemy", wow! - The exaggerations (despite being here, allegedly, >> softened by the word "somehow") seem to have become in vogue, lately. >> (Formerly I saw such argumentation paths prevalently in one specific >> poster's posts only. Communication style seems to be infectious. :-) > > I thought the term "blasphemy" was so obviously an exaggeration that it > could not be taken realistically. [...] No worries. (You may have noticed my smiley?) But the intention of my post was also to make obvious to better not foster such language, even if it was meant as "accentuation". (You know how pathological some posters can get in that respect.) Janis
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Keith Thompson
Date: Fri, 06 Nov 2026 18:50
Date: Fri, 06 Nov 2026 18:50
68 lines
3568 bytes
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 */
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Chris M. Thomasson
Date: Fri, 06 Nov 2026 21:16
Date: Fri, 06 Nov 2026 21:16
26 lines
2515 bytes
2515 bytes
On 11/6/2026 7:56 AM, Scott Lurndal wrote: > Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes: >> On 2026-11-06 00:42, Lynn McGuire wrote: >>> Hi, >>> >>> Does an expression in a logical statement need parenthesis for proper >>> evaluation in C and/or C++? >> >> No, below (assuming i1 and j1 are arithmetic types (and not used >> as "camouflaged" booleans) there's no parenthesis necessary. >> >> The necessity of parentheses depends on the operators used. In >> "C" the multiplication has higher precedence than the comparison. >> >> I suggest to get an Operator Precedence Table from the Net and >> inspect it until you got familiar with the operator precedences. >> Most precedences are anyway sensibly defined as you'd expect it. >> But be careful when using bit-expressions with '&', '|', and '^' >> especially if used together with the comparison operators. > > Lynn has been working on his "fortran" -> "C++" conversion > for over a decade now. That he isn't familar with the > C operator precedence table is rather frightening. > Well, yeah. Shit.
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Lynn McGuire
Date: Fri, 06 Nov 2026 21:19
Date: Fri, 06 Nov 2026 21:19
31 lines
2665 bytes
2665 bytes
On 11/6/2026 9:56 AM, Scott Lurndal wrote: > Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes: >> On 2026-11-06 00:42, Lynn McGuire wrote: >>> Hi, >>> >>> Does an expression in a logical statement need parenthesis for proper >>> evaluation in C and/or C++? >> >> No, below (assuming i1 and j1 are arithmetic types (and not used >> as "camouflaged" booleans) there's no parenthesis necessary. >> >> The necessity of parentheses depends on the operators used. In >> "C" the multiplication has higher precedence than the comparison. >> >> I suggest to get an Operator Precedence Table from the Net and >> inspect it until you got familiar with the operator precedences. >> Most precedences are anyway sensibly defined as you'd expect it. >> But be careful when using bit-expressions with '&', '|', and '^' >> especially if used together with the comparison operators. > > Lynn has been working on his "fortran" -> "C++" conversion > for over a decade now. That he isn't familar with the > C operator precedence table is rather frightening. Since 2022 on and off. Customers have demands on my time. You are confusing the upgrading of my Fortran code from Fortran II to Fortran 66 that did take roughly a decade. Lynn
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Chris M. Thomasson
Date: Fri, 06 Nov 2026 21:25
Date: Fri, 06 Nov 2026 21:25
67 lines
3891 bytes
3891 bytes
On 11/5/2026 11:49 PM, David Brown wrote:
> 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).
>
> 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.
>
> There is a proportion of programmers who think you should /always/ use
> parentheses to show the precedence of operators.
>
> Most programmers, I think, are in the middle. Parentheses here can make
> the expression clearer at a glance, but it is also obvious what it means
> when not using extra parentheses.
Agreed. I don't mind extra parentheses at all. Totally fine, and can
"help" in certain areas. I just happen to know about the order of
operations.
It is common to have parentheses in
> situations where the operator precedence is not as well known, or may
> differ between programming languages - mixing bitwise and logical
> operators and equality operators are examples.
>
> You can get a reasonable balance using gcc's warnings - these also have
> the big advantage of making it easy to check! "-Wparentheses" (enabled
> by -Wall) will catch, for example, "a < b == c" which parses as "a < (b
> == c)". If "-Wparentheses" does not lead to complaints, then your
> generated code is probably okay without the extra parentheses - but you
> can still add them here if you prefer.
>
> In general, I think you want your generated code to pass "gcc -O2 -Wall"
> cleanly (or the clang equivalent, which is /not/ -Weverything!). You
> may even aim for -Wextra.
>
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Lynn McGuire
Date: Fri, 06 Nov 2026 21:27
Date: Fri, 06 Nov 2026 21:27
82 lines
4400 bytes
4400 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
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Lynn McGuire
Date: Fri, 06 Nov 2026 21:29
Date: Fri, 06 Nov 2026 21:29
55 lines
3127 bytes
3127 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)...
Huh? I am confused. Aren't you missing a left parenthesis there?
Lynn
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: 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.
>
> [...]
>
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Lynn McGuire
Date: Fri, 06 Nov 2026 21:37
Date: Fri, 06 Nov 2026 21:37
54 lines
3426 bytes
3426 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.
...
Yes. I am tired of fixing the thousands of Fortran to C calls and C to
Fortran calls when we move to a new Fortran compiler or a new C/C++
compiler. This is one of the problems that has kept us on the obsolete
Watcom F77/C/C++ compilers for over 30 years.
I think I started putting C code into our Fortran calculation engine in
1992 when a Japanese customer needed more memory for their Inline
Fortran code inside our software (we have a Fortran 66 compiler and
interpreter built into our software). I finally gave up giving them a
special version every few months and moved all of the dynamic memory
allocation code to using malloc, realloc, and free. Worked like a champ
on the Unix and PC boxes, not so much on the mainframes and Vax
refrigerators that were going away anyway.
Lynn
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Steven G. Kargl
Date: Fri, 06 Nov 2026 21:48
Date: Fri, 06 Nov 2026 21:48
51 lines
3081 bytes
3081 bytes
On Fri, 6 Nov 2026 15:37:33 -0600, Lynn McGuire wrote:
> 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.
> ...
>
> Yes. I am tired of fixing the thousands of Fortran to C calls and C to
> Fortran calls when we move to a new Fortran compiler or a new C/C++
> compiler. This is one of the problems that has kept us on the obsolete
> Watcom F77/C/C++ compilers for over 30 years.
>
Fortran's ISO C binding feature fixed this Fortran <--> C issue some
20 years ago. Granted, CFI was not available until 2018.
--
steve
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Lawrence D’Oliveiro
Date: Fri, 06 Nov 2026 21:51
Date: Fri, 06 Nov 2026 21:51
13 lines
2081 bytes
2081 bytes
On Fri, 6 Nov 2026 15:27:44 -0600, Lynn McGuire wrote: > 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 thing I found useful in C++ code is using the explicit “xxx_cast<...>” operators instead of the catch-all C-style prefix-with-type-spec-in-parentheses. These are easier to search for, and also easier to make more specific (i.e. only using reinterpret_cast<> where absolutely necessary).
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Keith Thompson
Date: Fri, 06 Nov 2026 22:23
Date: Fri, 06 Nov 2026 22:23
20 lines
2086 bytes
2086 bytes
Lynn McGuire <lynnmcguire5@gmail.com> writes:
> On 11/6/2026 12:50 PM, Keith Thompson wrote:
[...]
>> 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)...
>
> Huh? I am confused. Aren't you missing a left parenthesis there?
Yes, that was just a typo. I meant:
if (j1 * i1 < 1)
My point is that *for me*, the fact that "*" binds more tightly than
"<" is so obvious that I find extra parentheses mildly distracting.
Of course both forms are obviously correct.
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Lynn McGuire
Date: Fri, 06 Nov 2026 22:34
Date: Fri, 06 Nov 2026 22:34
57 lines
3439 bytes
3439 bytes
On 11/6/2026 3:48 PM, Steven G. Kargl wrote:
> On Fri, 6 Nov 2026 15:37:33 -0600, Lynn McGuire wrote:
>
>> 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.
>> ...
>>
>> Yes. I am tired of fixing the thousands of Fortran to C calls and C to
>> Fortran calls when we move to a new Fortran compiler or a new C/C++
>> compiler. This is one of the problems that has kept us on the obsolete
>> Watcom F77/C/C++ compilers for over 30 years.
>>
>
> Fortran's ISO C binding feature fixed this Fortran <--> C issue some
> 20 years ago. Granted, CFI was not available until 2018.
I found the ISO C binding to be lacking and not type safe to my standard.
I also was not enthusiastic about installing it in thousands of places
in my code.
Lynn
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Oodini
Date: Fri, 06 Nov 2026 22:41
Date: Fri, 06 Nov 2026 22:41
9 lines
1473 bytes
1473 bytes
Le 06/11/2026 à 00:42, Lynn McGuire a écrit : > Does an expression in a logical statement need parenthesis for proper > evaluation in C and/or C++? No, but adding parentheses may be wished to make explicit the evaluation. Ie, it is suggested by MISRA C++:2023 : https://www.mathworks.com/help/bugfinder/ref/misracpp2023rule8.0.1.html
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: David Brown
Date: Sat, 07 Nov 2026 11:38
Date: Sat, 07 Nov 2026 11:38
28 lines
2601 bytes
2601 bytes
On 06/11/2026 19:18, Janis Papanagnou wrote: > On 2026-11-06 10:50, David Brown wrote: >> On 06/11/2026 09:17, Janis Papanagnou wrote: >>> On 2026-11-06 08:49, David Brown wrote: >>>> [...] >>>> >>>> There is a proportion of programmers who think it is somehow >>>> blasphemy to use more parentheses in an expression than strictly >>>> necessary. [...] >>> >>> "blasphemy", wow! - The exaggerations (despite being here, allegedly, >>> softened by the word "somehow") seem to have become in vogue, lately. >>> (Formerly I saw such argumentation paths prevalently in one specific >>> poster's posts only. Communication style seems to be infectious. :-) >> >> I thought the term "blasphemy" was so obviously an exaggeration that >> it could not be taken realistically. [...] > > No worries. (You may have noticed my smiley?) > > But the intention of my post was also to make obvious to better > not foster such language, even if it was meant as "accentuation". > (You know how pathological some posters can get in that respect.) > Yes, Poe's Law is a real phenomenon!
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: David Brown
Date: Sat, 07 Nov 2026 11:48
Date: Sat, 07 Nov 2026 11:48
99 lines
4600 bytes
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.
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Janis Papanagnou
Date: Sat, 07 Nov 2026 19:39
Date: Sat, 07 Nov 2026 19:39
30 lines
2970 bytes
2970 bytes
On 2026-11-07 12:48, David Brown wrote:
> [...]
>
> 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.
It might suffice for such an automation tasks to just mirror such
'goto' structures (unless you intend to create better structured
code through code transformations). - Not long ago I refactored a
legacy program to obtain an equivalent implementation in another
language and the de-spaghettifying turned out to have been really
nasty. (The code had severely convoluted 'goto's and not a single
structured element.) - In principal it's possible to de-'goto' any
source code to obtain structured code. Since I've no experience
with such tools I'm curious what experiences exists in that respect,
especially for trans-language transformations (from a heavily 'goto'
biased language (BASIC, FORTRAN?) to some structured language). -
While looking into the Net and concerning this thread I stumbled
across this reply, though:
"f2c or pet (for Fortran/C): Older research tools designed
to parse flat code graphs and reconstruct clean, structured
if/else and loop components."
which gave the impression that 'f2c' would be able to remove those
'goto's and so I'm wondering why there's (still) 'goto's in the
OP's sample code.
Janis
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Chris M. Thomasson
Date: Sat, 07 Nov 2026 20:29
Date: Sat, 07 Nov 2026 20:29
199 lines
8513 bytes
8513 bytes
On 11/7/2026 11:39 AM, Janis Papanagnou wrote:
> On 2026-11-07 12:48, David Brown wrote:
>> [...]
>>
>> 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.
>
> It might suffice for such an automation tasks to just mirror such
> 'goto' structures (unless you intend to create better structured
> code through code transformations). - Not long ago I refactored a
> legacy program to obtain an equivalent implementation in another
> language and the de-spaghettifying turned out to have been really
> nasty. (The code had severely convoluted 'goto's and not a single
> structured element.) - In principal it's possible to de-'goto' any
> source code to obtain structured code. Since I've no experience
> with such tools I'm curious what experiences exists in that respect,
> especially for trans-language transformations (from a heavily 'goto'
> biased language (BASIC, FORTRAN?) to some structured language). -
> While looking into the Net and concerning this thread I stumbled
> across this reply, though:
> Â "f2c or pet (for Fortran/C): Older research tools designed
> Â Â to parse flat code graphs and reconstruct clean, structured
> Â Â if/else and loop components."
> which gave the impression that 'f2c' would be able to remove those
> 'goto's and so I'm wondering why there's (still) 'goto's in the
> OP's sample code.
Fwiw, I ported some of my work over to AppleSoft BASIC just to show it
can be portable. But, my work needed some recursion. BASIC, good luck.
However, there is a way, giving BASIC a stack. So for a simple Koch
fractal based on any line:
https://pastebin.com/raw/Effeg8cK
100 REM ct_vfield_applesoft_basic
110 HOME
120 HGR: HCOLOR = 3: VTAB 22
130 PRINT "ct_vfield_applesoft_basic"
140 GOSUB 1000
150 GOSUB 3000
160 SP = 0
170 RS(SP, 0) = 0
180 RS(SP, 1) = -1
190 RS(SP, 2) = 0
200 RS(SP, 3) = 1
210 RS(SP, 4) = 0
220 GOSUB 8000
230 V1(1) = 0: V1(2) = 0: V1(3) = 1: V1(4) = 128
240 GOSUB 6000
245 PRINT "Chris Thomasson's Koch Complete!"
250 END
1000 REM ct_init
1010 PRINT "ct_init"
1020 DIM A0(6)
1030 DIM V0(4)
1040 DIM V1(4)
1050 DIM V2(4)
1060 DIM V3(4)
1070 DIM V4(4)
1080 DIM V5(4)
1090 RN = 3
1100 DIM RS(RN, 16)
1110 GOSUB 2000
1120 RETURN
2000 REM ct_init_plane
2010 PRINT "ct_init_plane"
2020 A0(1) = 279: REM m_plane.m_width
2030 A0(2) = 191: REM m_plane.m_height
2040 A0(3) = 0.0126106: REM m_plane.m_xstep
2050 A0(4) = 0.0126316: REM m_plane.m_ystep
2060 A0(5) = -1.75288: REM m_plane.m_axes.m_xmin
2070 A0(6) = 1.2: REM m_plane.m_axes.m_ymax
2080 RETURN
3000 REM ct_display_plane
3010 PRINT "ct_display_plane"
3020 FOR I0 = 1 TO 6
3030 PRINT "A0("; I0; ") = " A0(I0)
3040 NEXT I0
3050 RETURN
4000 REM ct_project_point
4010 REM PRINT "ct_project_point"
4020 V0(3) = (V0(1) - A0(5)) / A0(3)
4030 V0(4) = (A0(6) - V0(2)) / A0(4)
4040 IF V0(3) < 0 THEN V0(3) = INT(V0(3) - .5)
4050 IF V0(3) >= 0 THEN V0(3) = INT(V0(3) + .5)
4060 IF V0(4) < 0 THEN V0(4) = INT(V0(4) - .5)
4070 IF V0(4) >= 0 THEN V0(4) = INT(V0(4) + .5)
4080 RETURN
5000 REM ct_plot_point
5010 REM PRINT "ct_plot_point"
5020 GOSUB 4000
5030 IF V0(3) > -1 AND V0(3) <= A0(1) AND V0(4) > -1 AND V0(4) <=
A0(2) THEN HPLOT V0(3), V0(4)
5040 RETURN
6000 REM ct_plot_circle
6010 PRINT "ct_plot_circle"
6020 AB = 6.28318 / V1(4)
6030 FOR I1 = 0 TO 6.28318 STEP AB
6040 V0(1) = V1(1) + COS(I1) * V1(3)
6050 V0(2) = V1(2) + SIN(I1) * V1(3)
6060 GOSUB 5000
6070 NEXT I1
6080 RETURN
7000 REM ct_plot_line
7010 PRINT "ct_plot_line"
7020 V0(1) = V5(1): V0(2) = V5(2)
7030 GOSUB 4000
7040 IF V0(3) < 0 THEN V0(3) = 0
7050 IF V0(3) > A0(1) THEN V0(3) = A0(1)
7060 IF V0(4) < 0 THEN V0(4) = 0
7070 IF V0(4) > A0(2) THEN V0(4) = A0(2)
7080 HPLOT V0(3), V0(4)
7090 V0(1) = V5(3): V0(2) = V5(4)
7100 GOSUB 4000
7110 IF V0(3) < 0 THEN V0(3) = 0
7120 IF V0(3) > A0(1) THEN V0(3) = A0(1)
7130 IF V0(4) < 0 THEN V0(4) = 0
7140 IF V0(4) > A0(2) THEN V0(4) = A0(2)
7150 HPLOT TO V0(3), V0(4)
7160 RETURN
8000 REM ct_koch
8010 IF RS(SP, 0) >= RN THEN RETURN
8020 PRINT "ct_koch = "; RS(SP, 0); " "; RS(SP, 1); " "; RS(SP, 2);
" "; RS(SP, 3); " "; RS(SP, 4)"
8030 RS(SP, 5) = RS(SP, 3) - RS(SP, 1) : REM difx
8040 RS(SP, 6) = RS(SP, 4) - RS(SP, 2) : REM dify
8050 RS(SP, 7) = RS(SP, 1) + RS(SP, 5) / 2 : REM dify
8060 RS(SP, 8) = RS(SP, 2) + RS(SP, 6) / 2 : REM dify
8070 RS(SP, 9) = -RS(SP, 6) : REM perpx
8080 RS(SP, 10) = RS(SP, 5) : REM perpy
8090 RS(SP, 11) = RS(SP, 7) + RS(SP, 9) / 3 : REM tipx
8100 RS(SP, 12) = RS(SP, 8) + RS(SP, 10) / 3 : REM tipy
8110 RS(SP, 13) = RS(SP, 1) + RS(SP, 5) / 3 : REM k0x
8120 RS(SP, 14) = RS(SP, 2) + RS(SP, 6) / 3 : REM k0y
8130 RS(SP, 15) = RS(SP, 3) - RS(SP, 5) / 3 : REM k1x
8140 RS(SP, 16) = RS(SP, 4) - RS(SP, 6) / 3 : REM k1y
8145 IF RS(SP, 0) < RN - 1 GOTO 8230
8150 V5(1) = RS(SP, 1): V5(2) = RS(SP, 2): V5(3) = RS(SP, 13): V5(4)
= RS(SP, 14)
8160 GOSUB 7000
8170 V5(1) = RS(SP, 13): V5(2) = RS(SP, 14): V5(3) = RS(SP, 11):
V5(4) = RS(SP, 12)
8180 GOSUB 7000
8190 V5(1) = RS(SP, 11): V5(2) = RS(SP, 12): V5(3) = RS(SP, 15):
V5(4) = RS(SP, 16)
8200 GOSUB 7000
8210 V5(1) = RS(SP, 15): V5(2) = RS(SP, 16): V5(3) = RS(SP, 3):
V5(4) = RS(SP, 4)
8220 GOSUB 7000
8230 REM line 0
8240 SP = SP + 1
8250 RS(SP, 0) = RS(SP - 1, 0) + 1
8260 RS(SP, 1) = RS(SP - 1, 1)
8270 RS(SP, 2) = RS(SP - 1, 2)
8280 RS(SP, 3) = RS(SP - 1, 13)
8290 RS(SP, 4) = RS(SP - 1, 14)
8300 GOSUB 8000
8310 SP = SP - 1
8320 REM line 1
8330 SP = SP + 1
8340 RS(SP, 0) = RS(SP - 1, 0) + 1
8350 RS(SP, 1) = RS(SP - 1, 13)
8360 RS(SP, 2) = RS(SP - 1, 14)
8370 RS(SP, 3) = RS(SP - 1, 11)
8380 RS(SP, 4) = RS(SP - 1, 12)
8390 GOSUB 8000
8400 SP = SP - 1
8410 REM line 2
8420 SP = SP + 1
8430 RS(SP, 0) = RS(SP - 1, 0) + 1
8440 RS(SP, 1) = RS(SP - 1, 11)
8450 RS(SP, 2) = RS(SP - 1, 12)
8460 RS(SP, 3) = RS(SP - 1, 15)
8470 RS(SP, 4) = RS(SP - 1, 16)
8480 GOSUB 8000
8490 SP = SP - 1
8500 REM line 3
8510 SP = SP + 1
8520 RS(SP, 0) = RS(SP - 1, 0) + 1
8530 RS(SP, 1) = RS(SP - 1, 15)
8540 RS(SP, 2) = RS(SP - 1, 16)
8550 RS(SP, 3) = RS(SP - 1, 3)
8560 RS(SP, 4) = RS(SP - 1, 4)
8570 GOSUB 8000
8580 SP = SP - 1
8590 RETURN
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Lynn McGuire
Date: Sat, 07 Nov 2026 20:39
Date: Sat, 07 Nov 2026 20:39
42 lines
3559 bytes
3559 bytes
On 11/7/2026 1:39 PM, Janis Papanagnou wrote: > On 2026-11-07 12:48, David Brown wrote: >> [...] >> >> 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. > > It might suffice for such an automation tasks to just mirror such > 'goto' structures (unless you intend to create better structured > code through code transformations). - Not long ago I refactored a > legacy program to obtain an equivalent implementation in another > language and the de-spaghettifying turned out to have been really > nasty. (The code had severely convoluted 'goto's and not a single > structured element.) - In principal it's possible to de-'goto' any > source code to obtain structured code. Since I've no experience > with such tools I'm curious what experiences exists in that respect, > especially for trans-language transformations (from a heavily 'goto' > biased language (BASIC, FORTRAN?) to some structured language). - > While looking into the Net and concerning this thread I stumbled > across this reply, though: >  "f2c or pet (for Fortran/C): Older research tools designed >   to parse flat code graphs and reconstruct clean, structured >   if/else and loop components." > which gave the impression that 'f2c' would be able to remove those > 'goto's and so I'm wondering why there's (still) 'goto's in the > OP's sample code. > > Janis F2C is automagically restructuring my code to the first level. Maybe the second level sometimes. The number of gotos is reduced by 80 or 90%. Way past the point that I don't care. If a goto is jumping halfway down a method then replacing it with a monster if then is just crazy so F2C skips that case. I am not modifying F2C anymore. If wanted, I can post comparisons of a couple of my subroutines and the resulting methods. Lynn
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Janis Papanagnou
Date: Sun, 08 Nov 2026 00:30
Date: Sun, 08 Nov 2026 00:30
33 lines
2939 bytes
2939 bytes
On 2026-11-07 21:39, Lynn McGuire wrote: > On 11/7/2026 1:39 PM, Janis Papanagnou wrote: >> [...] >> While looking into the Net and concerning this thread I stumbled >> across this reply, though: >>   "f2c or pet (for Fortran/C): Older research tools designed >>    to parse flat code graphs and reconstruct clean, structured >>    if/else and loop components." >> which gave the impression that 'f2c' would be able to remove those >> 'goto's and so I'm wondering why there's (still) 'goto's in the >> OP's sample code. > > F2C is automagically restructuring my code to the first level. Maybe > the second level sometimes. The number of gotos is reduced by 80 or > 90%. Way past the point that I don't care. If a goto is jumping > halfway down a method then replacing it with a monster if then is just > crazy so F2C skips that case. I am not modifying F2C anymore. Thanks for that background information. > If wanted, I can post comparisons of a couple of my subroutines and the > resulting methods. Don't bother, since I'm not doing Fortran, I was just interested in principle here. Your numbers of 80-90% reduction is, I think, quite good already. But given that your C-code sample's label number is still "L463" I don't want to see that code; I'm still traumatized by the code that I had tried to de-goto-fy not long ago. Janis
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Janis Papanagnou
Date: Sun, 08 Nov 2026 00:39
Date: Sun, 08 Nov 2026 00:39
17 lines
2154 bytes
2154 bytes
On 2026-11-07 21:29, Chris M. Thomasson wrote: > Fwiw, I ported some of my work over to AppleSoft BASIC just to show it > can be portable. But, my work needed some recursion. BASIC, good luck. > However, there is a way, giving BASIC a stack. So for a simple Koch > fractal based on any line: > [snip] > 4040Â Â Â Â IF V0(3) < 0 THEN V0(3) = INT(V0(3) - .5) It's obviously at least a dialect that allowed a statement after the 'then', as opposed to just a line number (as it had been in the early dialects). Having only absolute jumps and conditional jumps is really a pain. Janis > [...]
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Lynn McGuire
Date: Sun, 08 Nov 2026 01:13
Date: Sun, 08 Nov 2026 01:13
38 lines
3125 bytes
3125 bytes
On 11/7/2026 6:30 PM, Janis Papanagnou wrote: > On 2026-11-07 21:39, Lynn McGuire wrote: >> On 11/7/2026 1:39 PM, Janis Papanagnou wrote: >>> [...] >>> While looking into the Net and concerning this thread I stumbled >>> across this reply, though: >>>   "f2c or pet (for Fortran/C): Older research tools designed >>>    to parse flat code graphs and reconstruct clean, structured >>>    if/else and loop components." >>> which gave the impression that 'f2c' would be able to remove those >>> 'goto's and so I'm wondering why there's (still) 'goto's in the >>> OP's sample code. >> >> F2C is automagically restructuring my code to the first level. Maybe >> the second level sometimes. The number of gotos is reduced by 80 or >> 90%. Way past the point that I don't care. If a goto is jumping >> halfway down a method then replacing it with a monster if then is just >> crazy so F2C skips that case. I am not modifying F2C anymore. > > Thanks for that background information. > >> If wanted, I can post comparisons of a couple of my subroutines and >> the resulting methods. > > Don't bother, since I'm not doing Fortran, I was just interested > in principle here. > > Your numbers of 80-90% reduction is, I think, quite good already. > But given that your C-code sample's label number is still "L463" > I don't want to see that code; I'm still traumatized by the code > that I had tried to de-goto-fy not long ago. > > Janis At least I do not have any "come from"s in my code. Lynn
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Janis Papanagnou
Date: Sun, 08 Nov 2026 08:55
Date: Sun, 08 Nov 2026 08:55
13 lines
1913 bytes
1913 bytes
On 2026-11-08 02:13, Lynn McGuire wrote: > On 11/7/2026 6:30 PM, Janis Papanagnou wrote: >> [...] I'm still traumatized by the code >> that I had tried to de-goto-fy not long ago. > > At least I do not have any "come from"s in my code. :-) I suppose you have Intercal in mind? ;-) Janis
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Andrey Tarasevich
Date: Mon, 09 Nov 2026 07:32
Date: Mon, 09 Nov 2026 07:32
27 lines
2031 bytes
2031 bytes
On Thu 11/5/2026 3:42 PM, Lynn McGuire wrote:
> 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;
> }
>
The whole `j1 * i1 < 1` is an expression in this case. It is parsed in
accordance with the grammar, which ultimately makes it equivalent to
`(j1 * i1) < 1`.
Your question seems to suggest that the `j1 * i1` part somehow qualifies
as an expression, while the rest of it does not. That's not how it
works. The language does not give the `j1 * i1` part any special status.
--
Best regards,
Andrey
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Bonita Montero
Date: Mon, 09 Nov 2026 09:03
Date: Mon, 09 Nov 2026 09:03
10 lines
1615 bytes
1615 bytes
Am 06.11.2026 um 00:42 schrieb Lynn McGuire:
> if (j1 * i1 < 1) {
> Â Â Â goto L463;
> }
> ...
> if ((j1 * i1) < 1) {
> Â Â Â goto L463;
> }
The latter one leads to more optimized code !
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: James Kuyper
Date: Mon, 09 Nov 2026 11:00
Date: Mon, 09 Nov 2026 11:00
34 lines
2759 bytes
2759 bytes
On 2026-11-09 02:32, Andrey Tarasevich wrote:
> On Thu 11/5/2026 3:42 PM, Lynn McGuire wrote:
>> 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;
>> }
>>
> The whole `j1 * i1 < 1` is an expression in this case. It is parsed in
> accordance with the grammar, which ultimately makes it equivalent to
> `(j1 * i1) < 1`.
>
> Your question seems to suggest that the `j1 * i1` part somehow qualifies
> as an expression, while the rest of it does not. That's not how it
> works. The language does not give the `j1 * i1` part any special status.
You are correct, parentheses are not needed. However, there's a related
question that could have a different answer: should an arithmetic
expression that is an operand of a comparison expression be
parenthesized - not because it needs the parenthesis, but to clarify
what the grammar already guarantees?
I tend not to use unnecessary parentheses, and I know the grammar well
enough to correctly identify them - but many people don't know the
grammar that well, which might include the next person to maintain my
code. There are reasonable arguments that I should use parentheses more
than I actually do, for the benefit of such people.
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Lynn McGuire
Date: Mon, 09 Nov 2026 20:24
Date: Mon, 09 Nov 2026 20:24
19 lines
2043 bytes
2043 bytes
On 11/8/2026 2:55 AM, Janis Papanagnou wrote:
> On 2026-11-08 02:13, Lynn McGuire wrote:
>> On 11/7/2026 6:30 PM, Janis Papanagnou wrote:
>>> [...]Â I'm still traumatized by the code
>>> that I had tried to de-goto-fy not long ago.
>>
>> At least I do not have any "come from"s in my code.
>
> :-)
>
> I suppose you have Intercal in mind? ;-)
>
> Janis
Fortran of course.
https://en.wikipedia.org/wiki/COMEFROM
Lynn
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Janis Papanagnou
Date: Mon, 09 Nov 2026 20:42
Date: Mon, 09 Nov 2026 20:42
76 lines
5024 bytes
5024 bytes
On 2026-11-09 12:00, James Kuyper wrote:
> On 2026-11-09 02:32, Andrey Tarasevich wrote:
>> On Thu 11/5/2026 3:42 PM, Lynn McGuire wrote:
>>> 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;
>>> }
>>>
>> The whole `j1 * i1 < 1` is an expression in this case. It is parsed in
>> accordance with the grammar, which ultimately makes it equivalent to
>> `(j1 * i1) < 1`.
>>
>> Your question seems to suggest that the `j1 * i1` part somehow qualifies
>> as an expression, while the rest of it does not. That's not how it
>> works. The language does not give the `j1 * i1` part any special status.
> You are correct, parentheses are not needed. However, there's a related
> question that could have a different answer: should an arithmetic
> expression that is an operand of a comparison expression be
> parenthesized - not because it needs the parenthesis, but to clarify
> what the grammar already guarantees?
I observed that most grammars are consistently defined and have the
semantics what one expects. ("C" with &, |, ^ being with this detail
the obvious exception.) In some other well-known languages you even
need parentheses in expressions with mixed types. (Remember Pascal
with expressions like "(12 < 42) AND (33 >= 21)"; but here you will
just get a syntax error when omitting the parentheses, so it's safe.)
The problem with "C", beyond the mentioned bit-operations case, is
that there had been just one integral "type" and all operations were
applicable between integers, "characters", and "booleans", and that
they all "make sense" here. So type-safety of a language plays a role,
presuming the language (not "C") has a sensible differentiated set of
types. While for arithmetic the rules are (mostly) as you'd expect
them to be I'm usually using parenthesis to signify precedence within
the bool type in complex expressions containing mixtures of '&&' and
'||' - that's of course my personal thing.
> I tend not to use unnecessary parentheses, and I know the grammar well
> enough to correctly identify them - but many people don't know the
> grammar that well, which might include the next person to maintain my
> code. There are reasonable arguments that I should use parentheses more
> than I actually do, for the benefit of such people.
I'm "a bit" unsettled by the idea of a programmer who is unfamiliar
with the language in general or the grammar specifically! (I know
there's such folks writing programs.) I wouldn't write programs in
ways to satisfy such folks. I'd certainly write programs in ways to
keep the program maintainable focusing on the language specifics not
imagining that the piece of code might be handled by a Neanderthal.
(But that's also a topic of management; will they employ professional
programmers, do they install coding guidelines, will their processes
include QA means, etc. That's handled primarily on an organizational
level. For private programming it's even less an issue to consider
the worst case of some uninitiated working with your programs.)
I think the most benefit for parentheses is to visually structure
expressions that are very complex. While other means support that,
like in-line spacing and formatting an expression across more lines,
the parentheses are the prominent way to make the expression actually
*do* what is written so are unambiguous (as is splitting an expression
explicitly into sub-expressions).
Janis
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Janis Papanagnou
Date: Mon, 09 Nov 2026 20:51
Date: Mon, 09 Nov 2026 20:51
23 lines
2245 bytes
2245 bytes
On 2026-11-09 21:24, Lynn McGuire wrote: > On 11/8/2026 2:55 AM, Janis Papanagnou wrote: >> On 2026-11-08 02:13, Lynn McGuire wrote: >>> On 11/7/2026 6:30 PM, Janis Papanagnou wrote: >>>> [...]Â I'm still traumatized by the code >>>> that I had tried to de-goto-fy not long ago. >>> >>> At least I do not have any "come from"s in my code. >> >> :-) >> >> I suppose you have Intercal in mind? ;-) > > Fortran of course. > Â Â https://en.wikipedia.org/wiki/COMEFROM Jesus! 8-o Interesting article; I didn't know that "joke" was considered also by those more serious languages. Janis
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Lawrence D’Oliveiro
Date: Mon, 09 Nov 2026 22:41
Date: Mon, 09 Nov 2026 22:41
14 lines
1916 bytes
1916 bytes
On Mon, 9 Nov 2026 06:00:40 -0500, James Kuyper wrote: > I tend not to use unnecessary parentheses, and I know the grammar > well enough to correctly identify them - but many people don't know > the grammar that well, which might include the next person to > maintain my code. Even if they haven’t committed the precedence table to memory, surely they have the ability to look things up online <https://en.cppreference.com/c/language/operator_precedence>. If someone has regular trouble with certain language features, why aren’t pages that clarify those very issues not already in their browser bookmarks?
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Keith Thompson
Date: Tue, 10 Nov 2026 00:54
Date: Tue, 10 Nov 2026 00:54
30 lines
2694 bytes
2694 bytes
Lawrence D’Oliveiro <ldo@nz.invalid> writes:
> On Mon, 9 Nov 2026 06:00:40 -0500, James Kuyper wrote:
>> I tend not to use unnecessary parentheses, and I know the grammar
>> well enough to correctly identify them - but many people don't know
>> the grammar that well, which might include the next person to
>> maintain my code.
>
> Even if they haven’t committed the precedence table to memory, surely
> they have the ability to look things up online
> <https://en.cppreference.com/c/language/operator_precedence>.
>
> If someone has regular trouble with certain language features, why
> aren’t pages that clarify those very issues not already in their
> browser bookmarks?
If I haven't memorized all the precedence levels, I greatly prefer
an expression I can read at a glance to one that requires me to
consult some document before I can be sure what it means, just so
I can continue to the next line of code.
Just one example: I couldn't tell you whether `^` or `|` binds more
tightly without looking it up. If you can, that's great.
Preferences for *how many* strictly semantically unnecessary
parentheses are appropriate vary greatly, but few C programmers
would insist on none.
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Chris M. Thomasson
Date: Tue, 10 Nov 2026 01:05
Date: Tue, 10 Nov 2026 01:05
30 lines
2799 bytes
2799 bytes
On 11/9/2026 4:54 PM, Keith Thompson wrote: > Lawrence D’Oliveiro <ldo@nz.invalid> writes: >> On Mon, 9 Nov 2026 06:00:40 -0500, James Kuyper wrote: >>> I tend not to use unnecessary parentheses, and I know the grammar >>> well enough to correctly identify them - but many people don't know >>> the grammar that well, which might include the next person to >>> maintain my code. >> >> Even if they haven’t committed the precedence table to memory, surely >> they have the ability to look things up online >> <https://en.cppreference.com/c/language/operator_precedence>. >> >> If someone has regular trouble with certain language features, why >> aren’t pages that clarify those very issues not already in their >> browser bookmarks? > > If I haven't memorized all the precedence levels, I greatly prefer > an expression I can read at a glance to one that requires me to > consult some document before I can be sure what it means, just so > I can continue to the next line of code. > > Just one example: I couldn't tell you whether `^` or `|` binds more > tightly without looking it up. If you can, that's great. > > Preferences for *how many* strictly semantically unnecessary > parentheses are appropriate vary greatly, but few C programmers > would insist on none. > Perfectly fair enough. Good.
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Lynn McGuire
Date: Tue, 10 Nov 2026 04:39
Date: Tue, 10 Nov 2026 04:39
40 lines
3246 bytes
3246 bytes
On 11/9/2026 6:54 PM, Keith Thompson wrote: > Lawrence D’Oliveiro <ldo@nz.invalid> writes: >> On Mon, 9 Nov 2026 06:00:40 -0500, James Kuyper wrote: >>> I tend not to use unnecessary parentheses, and I know the grammar >>> well enough to correctly identify them - but many people don't know >>> the grammar that well, which might include the next person to >>> maintain my code. >> >> Even if they haven’t committed the precedence table to memory, surely >> they have the ability to look things up online >> <https://en.cppreference.com/c/language/operator_precedence>. >> >> If someone has regular trouble with certain language features, why >> aren’t pages that clarify those very issues not already in their >> browser bookmarks? > > If I haven't memorized all the precedence levels, I greatly prefer > an expression I can read at a glance to one that requires me to > consult some document before I can be sure what it means, just so > I can continue to the next line of code. > > Just one example: I couldn't tell you whether `^` or `|` binds more > tightly without looking it up. If you can, that's great. > > Preferences for *how many* strictly semantically unnecessary > parentheses are appropriate vary greatly, but few C programmers > would insist on none. I ship my software written in four different software languages. C++, Fortran, Visual Basic, and C#. Remembering the nuances of each is tricky. I find it best to be safe. I have shipped software in about a dozen software languages in my 51 year career. C++, Fortran IV (66), Fortran 77, Visual Basic, C#, Turbo Pascal, Basic, Turbo C, Unix C, IBM 370 Assembler, Intel x86 Assembler, AWK. I think that I am leaving out a couple that I cannot remember at the moment. Lynn
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Chris M. Thomasson
Date: Tue, 10 Nov 2026 06:25
Date: Tue, 10 Nov 2026 06:25
46 lines
3425 bytes
3425 bytes
On 11/9/2026 8:39 PM, Lynn McGuire wrote: > On 11/9/2026 6:54 PM, Keith Thompson wrote: >> Lawrence D’Oliveiro <ldo@nz.invalid> writes: >>> On Mon, 9 Nov 2026 06:00:40 -0500, James Kuyper wrote: >>>> I tend not to use unnecessary parentheses, and I know the grammar >>>> well enough to correctly identify them - but many people don't know >>>> the grammar that well, which might include the next person to >>>> maintain my code. >>> >>> Even if they haven’t committed the precedence table to memory, surely >>> they have the ability to look things up online >>> <https://en.cppreference.com/c/language/operator_precedence>. >>> >>> If someone has regular trouble with certain language features, why >>> aren’t pages that clarify those very issues not already in their >>> browser bookmarks? >> >> If I haven't memorized all the precedence levels, I greatly prefer >> an expression I can read at a glance to one that requires me to >> consult some document before I can be sure what it means, just so >> I can continue to the next line of code. >> >> Just one example: I couldn't tell you whether `^` or `|` binds more >> tightly without looking it up. If you can, that's great. >> >> Preferences for *how many* strictly semantically unnecessary >> parentheses are appropriate vary greatly, but few C programmers >> would insist on none. > > I ship my software written in four different software languages. C++, > Fortran, Visual Basic, and C#. Remembering the nuances of each is > tricky. I find it best to be safe. > > I have shipped software in about a dozen software languages in my 51 > year career. C++, Fortran IV (66), Fortran 77, Visual Basic, VB 6? Do you use access as well? > C#, Turbo > Pascal, Basic, Turbo C, Unix C, IBM 370 Assembler, Intel x86 Assembler, > AWK. I think that I am leaving out a couple that I cannot remember at > the moment. > > Lynn >
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: David Brown
Date: Tue, 10 Nov 2026 07:36
Date: Tue, 10 Nov 2026 07:36
42 lines
3327 bytes
3327 bytes
On 10/11/2026 01:54, Keith Thompson wrote: > Lawrence D’Oliveiro <ldo@nz.invalid> writes: >> On Mon, 9 Nov 2026 06:00:40 -0500, James Kuyper wrote: >>> I tend not to use unnecessary parentheses, and I know the grammar >>> well enough to correctly identify them - but many people don't know >>> the grammar that well, which might include the next person to >>> maintain my code. >> >> Even if they haven’t committed the precedence table to memory, surely >> they have the ability to look things up online >> <https://en.cppreference.com/c/language/operator_precedence>. >> >> If someone has regular trouble with certain language features, why >> aren’t pages that clarify those very issues not already in their >> browser bookmarks? > > If I haven't memorized all the precedence levels, I greatly prefer > an expression I can read at a glance to one that requires me to > consult some document before I can be sure what it means, just so > I can continue to the next line of code. > > Just one example: I couldn't tell you whether `^` or `|` binds more > tightly without looking it up. If you can, that's great. Speaking as someone who uses the bit operations more than most programmers, I can't tell you that either - I use parentheses to make it clear. I have other things on which to use my limited brainpower! There are things that it is perhaps better not to know - because then you write your code in a clearer fashion that is obvious to experts and newcomers alike. (I am not necessarily talking about newcomers to C or C++ - people work with these languages in wildly different fields, and work on wildly different types of code and styles of coding.) > > Preferences for *how many* strictly semantically unnecessary > parentheses are appropriate vary greatly, but few C programmers > would insist on none. >
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: Fred. Zwarts
Date: Tue, 10 Nov 2026 08:58
Date: Tue, 10 Nov 2026 08:58
13 lines
1632 bytes
1632 bytes
Op 09.nov.2026 om 10:03 schreef Bonita Montero:
> Am 06.11.2026 um 00:42 schrieb Lynn McGuire:
>
>> if (j1 * i1 < 1) {
>> Â Â Â Â goto L463;
>> }
>> ...
>> if ((j1 * i1) < 1) {
>> Â Â Â Â goto L463;
>> }
> The latter one leads to more optimized code !
Really? Why?
Re: does an expression in a logical statement need parenthesis for proper evaluation?
Author: David Brown
Date: Tue, 10 Nov 2026 09:32
Date: Tue, 10 Nov 2026 09:32
16 lines
1760 bytes
1760 bytes
On 10/11/2026 09:58, Fred. Zwarts wrote:
> Op 09.nov.2026 om 10:03 schreef Bonita Montero:
>> Am 06.11.2026 um 00:42 schrieb Lynn McGuire:
>>
>>> if (j1 * i1 < 1) {
>>> Â Â Â Â goto L463;
>>> }
>>> ...
>>> if ((j1 * i1) < 1) {
>>> Â Â Â Â goto L463;
>>> }
>> The latter one leads to more optimized code !
>
> Really? Why?
I /presume/ Bonita was joking.
Page 1 of 4 • 158 total messages
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads