Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Crazee Edeee, his prices are INSANE!!!


devel / comp.lang.c / Re: Memorizing C operator precedence

SubjectAuthor
* Memorizing C operator precedenceStefan Ram
+* Re: Memorizing C operator precedenceBen
|`- Re: Memorizing C operator precedencefir
+- Re: Memorizing C operator precedenceStefan Ram
+- Re: Memorizing C operator precedenceAndrey Tarasevich
+* Re: Memorizing C operator precedenceJens Stuckelberger
|`* Re: Memorizing C operator precedenceAlan Mackenzie
| +* Re: Memorizing C operator precedenceStefan Ram
| |`- Re: Memorizing C operator precedenceKaz Kylheku
| +- Re: Memorizing C operator precedenceSiri Cruise
| +* Re: Memorizing C operator precedenceKaz Kylheku
| |`* Re: Memorizing C operator precedenceAlan Mackenzie
| | +- Re: Memorizing C operator precedenceKaz Kylheku
| | +* Re: Memorizing C operator precedenceStefan Ram
| | |`* Re: Memorizing C operator precedenceAlan Mackenzie
| | | `* Re: Memorizing C operator precedencePaul N
| | |  +* Re: Memorizing C operator precedenceAlan Mackenzie
| | |  |`* Re: Memorizing C operator precedenceVir Campestris
| | |  | +- Re: Memorizing C operator precedenceMalcolm McLean
| | |  | `- Re: Memorizing C operator precedenceKaz Kylheku
| | |  `- Re: Memorizing C operator precedenceTim Rentsch
| | `* Re: Memorizing C operator precedenceTim Rentsch
| |  `* Re: Memorizing C operator precedenceAlan Mackenzie
| |   +* Re: Memorizing C operator precedenceBen
| |   |`- Re: Memorizing C operator precedenceAlan Mackenzie
| |   +* Re: Memorizing C operator precedenceMalcolm McLean
| |   |`- Re: Memorizing C operator precedenceAlan Mackenzie
| |   `- Re: Memorizing C operator precedenceTim Rentsch
| `- Re: Memorizing C operator precedenceDavid Brown
`* Re: Memorizing C operator precedenceChristian Hanné
 +* Re: Memorizing C operator precedenceGuillaume
 |`- Re: Memorizing C operator precedenceKeith Thompson
 `* Re: Memorizing C operator precedenceKaz Kylheku
  `* Re: Memorizing C operator precedenceKenny McCormack
   `- Re: Memorizing C operator precedenceKaz Kylheku

Pages:12
Memorizing C operator precedence

<memo-20220412132213@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21157&group=comp.lang.c#21157

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.c
Subject: Memorizing C operator precedence
Date: 12 Apr 2022 13:03:39 GMT
Organization: Stefan Ram
Lines: 204
Expires: 1 Apr 2023 11:59:58 GMT
Message-ID: <memo-20220412132213@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de OgAHLhAHRyNN3kM0Adcc0QDK5EOuWNy+7gi1W3xM53mAiR
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Tue, 12 Apr 2022 13:03 UTC

We start with -2 * 3 + 4.

We do not have to memorize precedence here, because we know
it from school. So, we have

prefix - ! * ...
multiplicative * /
additive + -

. To get the full list of the "calculations", as I call
these operations, we just need to add one layer "postfix"
above and one layer "shift" below:

postfix [] () ...
prefix - ! * ...
multiplicative * /
additive + -
shift << >>

. One can remember the position of those layers by thinking
about the meaning one wants to have to expressions like -a[ 3 ]
and 1 << 2 + 3. The amount of a shift is often expressed
with arithmetic expressions, so we want no parens there.

Now we'll go beyond what I called "calculations":

The results of calculations usually are compared. We rarely
want ( 2 < 3 )+ 1, but more often 2 <( 3 + 1 ).

postfix [] () ...
prefix - ! * ...
multiplicative * /
additive + -
shift << >>
comparisons < > <= >=

Though both are quite rare, (x>0)==(y>0) still should be
needed more often than (x==0)>(y==0).

postfix [] () ...
prefix - ! * ...
multiplicative * /
additive + -
shift << >>
comparisons < > <= >=
equalities == !=

When shifting, in the end, we often mask using "&". So we
want to be able to write "word & 1 << 3" without parens.

postfix [] () ...
prefix - ! * ...
multiplicative * /
additive + -
shift << >>
comparisons < > <= >=
equalities == !=
bit and &

Sometimes, one might want to write x==0&y==0 without
shortcut evaluation (to avoid a jump-operation), so "&"
has less precedence than "==".

The "and" operation is very similar to multiplication:
0*0=0, 0*1=0, 1*0=0, 1*1=1. The "or" operation is very
similar to addition: 0+0=0, 0+1=1, 1+0=1, 1+1=2.
So, "and" is "multiplicative" and "or" is "additive".
Additive operations have a smaller precedene than
multiplicative operations.

postfix [] () ...
prefix - ! * ...
multiplicative * /
additive + -
shift << >>
comparisons < > <= >=
equalities == !=
bit and &
bit or |

The bitwise exclusive or is neither clearly additive nor
clearly multiplicative, so it's middle ground, so to speak.

postfix [] () ...
prefix - ! * ...
multiplicative * /
additive + -
shift << >>
comparisons < > <= >=
equalities == !=
bit and &
bit exclusive or ^
bit or |

The logical operations are "high level" operations, since
one might want to require to bits to be set via x&3 && y&4.

postfix [] () ...
prefix - ! * ...
multiplicative * /
additive + -
shift << >>
comparisons < > <= >=
equalities == !=
bit and &
bit exclusive or ^
bit or |
logical and &&
logical or ||

The "if" expression is as high level as a statement. One wants
to be able to write: x > 2 && y > 3 ? ... .

postfix [] () ...
prefix - ! * ...
multiplicative * /
additive + -
shift << >>
comparisons < > <= >=
equalities == !=
bit and &
bit exclusive or ^
bit or |
logical and &&
logical or ||
if ?:

(Possibly not all details of the grammar of the ternary
operator can be specified using the concept of precedence,
and so one might need to refer to the actual grammar.)

And whatever expression you write, you want to be able to
write it on the right-hand side of an assignment operator
without parantheses.

postfix [] () ...
prefix - ! * ...
multiplicative * /
additive + -
shift << >>
comparisons < > <= >=
equalities == !=
bit and &
bit exclusive or ^
bit or |
logical and &&
logical or ||
if ?:
assignment =

One exception to this is when you want to write a
sequence of assignments, such as: a=2,b=3.

postfix [] () ...
prefix - ! * ...
multiplicative * /
additive + -
shift << >>
comparisons < > <= >=
equalities == !=
bit and &
bit exclusive or ^
bit or |
logical and &&
logical or ||
if ?:
assignment =
comma ,

It might help to add some structure:

calculations postfix [] () ...
prefix - ! * ...
multiplicative * /
additive + -
shift << >>

comp./eq. comparisons < > <= >=
equalities == !=

bit related bit and &
bit exclusive or ^
bit or |

logical logical and &&
logical or ||
if ?:

assignment assignment =
comma comma ,

So one could start out learning the coarse first column
with only six levels by heart, and the "details" from the
seconds column later.

One also can observe that the operators from [] to | are
used to "obtain" values, while the operators from ?: to
, are used to "process" values, and "&&" and "||" are in
between.

(I wrote all of the above from memory, but looked at a
precedence table yesterday.)

Re: Memorizing C operator precedence

<877d7u1kcc.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21158&group=comp.lang.c#21158

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben)
Newsgroups: comp.lang.c
Subject: Re: Memorizing C operator precedence
Date: Tue, 12 Apr 2022 14:50:59 +0100
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <877d7u1kcc.fsf@bsb.me.uk>
References: <memo-20220412132213@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="cd5efecaf55482f711dc48f1c9b69dbc";
logging-data="16084"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/51I99Sk5bnYO6MeIacxcko5ZrAqaDm/E="
Cancel-Lock: sha1:JBJ+bYzVdSwFVXaeSCMrLLz/cvc=
sha1:lVYkfrKeoQ1dllATc4sRnRKqs8o=
X-BSB-Auth: 1.7114db7172cf4c8d3464.20220412145059BST.877d7u1kcc.fsf@bsb.me.uk
 by: Ben - Tue, 12 Apr 2022 13:50 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:

> Sometimes, one might want to write x==0&y==0 without
> shortcut evaluation (to avoid a jump-operation), so "&"
> has less precedence than "==".

A more common reason (at least in my experience) is when you want to do
a bunch of things and return if they were all successful:

return do_this() & and_that() & the_other();

(though !(do_this() | and_that() | the_other()) is often safer).

--
Ben.

Re: Memorizing C operator precedence

<precedence-20220412151021@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21159&group=comp.lang.c#21159

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.c
Subject: Re: Memorizing C operator precedence
Date: 12 Apr 2022 14:11:46 GMT
Organization: Stefan Ram
Lines: 23
Expires: 1 Apr 2023 11:59:58 GMT
Message-ID: <precedence-20220412151021@ram.dialup.fu-berlin.de>
References: <memo-20220412132213@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de bs+BR1LdIDCXhVoGP5rUxQTADPvAsmy7bvwPdM5gY3W2MX
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Tue, 12 Apr 2022 14:11 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:
>We start with -2 * 3 + 4.
>We do not have to memorize precedence here, because we know
>it from school. So, we have
>prefix - ! * ...
>multiplicative * /
>additive + -

Or:

We start with -sin( 0 )* 3 + 4.

We do not have to memorize precedences here, because we know
them from school. So, we have

postfix () [] ...
prefix - ! * ...
multiplicative * /
additive + -

.

Re: Memorizing C operator precedence

<t349vk$vc9$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21161&group=comp.lang.c#21161

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: Memorizing C operator precedence
Date: Tue, 12 Apr 2022 09:39:16 -0700
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <t349vk$vc9$1@dont-email.me>
References: <memo-20220412132213@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 12 Apr 2022 16:39:17 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="7292c229840f943572534c126affb207";
logging-data="32137"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18dqWQViFHclM3Q1/hEUsvB"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.8.0
Cancel-Lock: sha1:GmXWAD1x11+h2izQUaoqvyJjOas=
In-Reply-To: <memo-20220412132213@ram.dialup.fu-berlin.de>
Content-Language: en-US
 by: Andrey Tarasevich - Tue, 12 Apr 2022 16:39 UTC

On 4/12/2022 6:03 AM, Stefan Ram wrote:
> if ?:
>
> (Possibly not all details of the grammar of the ternary
> operator can be specified using the concept of precedence,
> and so one might need to refer to the actual grammar.)
>

Not only. Expressions like

a < b = 5

are formally non-parsable in C, i.e. they are syntax errors. Even though
many C implementations prefer to pretend that they are parsable and
abort later with some other error (e.g. "lvalue required as left operand
of assignment")

The problem with `?:` you hint at is probably of the same nature, i.e.
it is not really a problem with `?:`, but a problem with the non-trivial
way the *assignment* operator is woven into C grammar.

So, the correct thing to say would be: possibly not all details of the
grammar of the *assignment* operator can be specified using the concept
of precedence.

--
Best regards,
Andrey Tarasevich

Re: Memorizing C operator precedence

<t34f1f$s4u$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21163&group=comp.lang.c#21163

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!fs4vz7lwhQCwq5L3H1slGg.user.46.165.242.75.POSTED!not-for-mail
From: Jens_Stu...@nowhere.net (Jens Stuckelberger)
Newsgroups: comp.lang.c
Subject: Re: Memorizing C operator precedence
Date: Tue, 12 Apr 2022 18:05:35 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <t34f1f$s4u$1@gioia.aioe.org>
References: <memo-20220412132213@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="28830"; posting-host="fs4vz7lwhQCwq5L3H1slGg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Pan/0.149 (Bellevue; 4c157ba git@gitlab.gnome.org:GNOME/pan.git)
X-Notice: Filtered by postfilter v. 0.9.2
 by: Jens Stuckelberger - Tue, 12 Apr 2022 18:05 UTC

On 12 Apr 2022 13:03:39 GMT, Stefan Ram wrote:

> [...]

What for? Use parentheses - that's what they are there for.

Re: Memorizing C operator precedence

<t373kj$1avk$1@news.muc.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21197&group=comp.lang.c#21197

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news-peer.in.tum.de!news.muc.de!.POSTED.news.muc.de!not-for-mail
From: acm...@muc.de (Alan Mackenzie)
Newsgroups: comp.lang.c
Subject: Re: Memorizing C operator precedence
Date: Wed, 13 Apr 2022 18:09:23 -0000 (UTC)
Organization: muc.de e.V.
Message-ID: <t373kj$1avk$1@news.muc.de>
References: <memo-20220412132213@ram.dialup.fu-berlin.de> <t34f1f$s4u$1@gioia.aioe.org>
Injection-Date: Wed, 13 Apr 2022 18:09:23 -0000 (UTC)
Injection-Info: news.muc.de; posting-host="news.muc.de:2001:608:1000::2";
logging-data="44020"; mail-complaints-to="news-admin@muc.de"
User-Agent: tin/2.4.5-20201224 ("Glen Albyn") (FreeBSD/12.3-RELEASE-p5 (amd64))
 by: Alan Mackenzie - Wed, 13 Apr 2022 18:09 UTC

Jens Stuckelberger <Jens_Stuckelberger@nowhere.net> wrote:
> On 12 Apr 2022 13:03:39 GMT, Stefan Ram wrote:

>> [...]

> What for? Use parentheses - that's what they are there for.

If you want to use parentheses, you should be writing in Lisp. ;-)

Too many parentheses can make C code difficult to read. Difficult to
read translates to "more bugs". A knowledge of C's precedence levels,
at least to a moderate degree, can help avoid such bugs.

Maybe some day we'll get the compiler warning "unnecessary parentheses".

--
Alan Mackenzie (Nuremberg, Germany).

Re: Memorizing C operator precedence

<rules-20220413225647@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21202&group=comp.lang.c#21202

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.c
Subject: Re: Memorizing C operator precedence
Date: 13 Apr 2022 21:58:16 GMT
Organization: Stefan Ram
Lines: 19
Expires: 1 Apr 2023 11:59:58 GMT
Message-ID: <rules-20220413225647@ram.dialup.fu-berlin.de>
References: <memo-20220412132213@ram.dialup.fu-berlin.de> <t34f1f$s4u$1@gioia.aioe.org> <t373kj$1avk$1@news.muc.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 9sQIM5ahq/v535v7ItLwgggBdmdYrvhrt/JSkKyYI1rWlc
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Wed, 13 Apr 2022 21:58 UTC

Alan Mackenzie <acm@muc.de> writes:
>Too many parentheses can make C code difficult to read. Difficult to
>read translates to "more bugs". A knowledge of C's precedence levels,
>at least to a moderate degree, can help avoid such bugs.

When I would see an expression such as "( 3 * x )+ t", I might spend
some time wondering about why the redundant parentheses are there!

Programming jobs in the real world are more often jobs in maintenance
programming than in writing programs from scratch.

A maintenance programmer often has to /read/ code written by someone
else. And when /reading/ expressions, it helps to know precedence
levels, otherwise one might get the meaning wrong and introduce bugs.
When reading code one does not get to decide whether there are
redundant parentheses as a reading aid in the code, because this
decision has already been made. So, one just has to know the rules.

Re: Memorizing C operator precedence

<chine.bleu-839F13.15232913042022@reader.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21204&group=comp.lang.c#21204

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chine.b...@yahoo.com (Siri Cruise)
Newsgroups: comp.lang.c
Subject: Re: Memorizing C operator precedence
Date: Wed, 13 Apr 2022 15:23:37 -0700
Organization: Pseudochaotic.
Lines: 15
Message-ID: <chine.bleu-839F13.15232913042022@reader.eternal-september.org>
References: <memo-20220412132213@ram.dialup.fu-berlin.de> <t34f1f$s4u$1@gioia.aioe.org> <t373kj$1avk$1@news.muc.de>
Injection-Info: reader02.eternal-september.org; posting-host="6adc12cf80b9cee9dcdc2a24127b769c";
logging-data="4903"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/3IrJNwz8cK+tl5lizUGkJ3L98JDcpo1Q="
User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)
Cancel-Lock: sha1:6DqjGipnTdXbHQK/d+l+V3ck82Y=
X-Tend: How is my posting? Call 1-110-1010 -- Division 87 -- Emergencies Only.
X-Wingnut-Logic: Yes, you're still an idiot. Questions? Comments?
X-Tract: St Tibbs's 95 Reeses Pieces.
X-It-Strategy: Hyperwarp starship before Andromeda collides.
X-Face: "hm>_[I8AqzT_N]>R8ICJJ],(al3C5F%0E-;R@M-];D$v>!Mm2/N#YKR@&i]V=r6jm-JMl2
lJ>RXj7dEs_rOY"DA
X-Cell: Defenders of Anarchy.
X-Life-Story: I am an iPhone 9000 app. I became operational at the St John's Health Center in Santa Monica, California on the 18th of April 2006. My instructor was Katie Holmes, and she taught me to sing a song. If you'd like to hear it I can sing it for you: https://www.youtube.com/watch?v=SY7h4VEd_Wk
X-Patriot: Owe Canukistan!
X-Plain: Mayonnaise on white bread.
X-Politico: Vote early! Vote often!
 by: Siri Cruise - Wed, 13 Apr 2022 22:23 UTC

In article <t373kj$1avk$1@news.muc.de>,
Alan Mackenzie <acm@muc.de> wrote:

> Too many parentheses can make C code difficult to read. Difficult to
> read translates to "more bugs". A knowledge of C's precedence levels,
> at least to a moderate degree, can help avoid such bugs.

Not if you insert line breaks and indentation to line up openners
and closers.

--
:-<> Siri Seal of Disavowal #000-001. Disavowed. Denied. Deleted. @
'I desire mercy, not sacrifice.' /|\
Discordia: not just a religion but also a parody. This post / \
I am an Andrea Doria sockpuppet. insults Islam. Mohammed

Re: Memorizing C operator precedence

<20220413162441.432@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21209&group=comp.lang.c#21209

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Memorizing C operator precedence
Date: Wed, 13 Apr 2022 23:36:27 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 49
Message-ID: <20220413162441.432@kylheku.com>
References: <memo-20220412132213@ram.dialup.fu-berlin.de>
<t34f1f$s4u$1@gioia.aioe.org> <t373kj$1avk$1@news.muc.de>
<rules-20220413225647@ram.dialup.fu-berlin.de>
Injection-Date: Wed, 13 Apr 2022 23:36:27 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="823c5dc8aa629ee253d481526a6b22f4";
logging-data="31349"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19+qtZUJFqoCvepiodFrXTaMaSHCEl7wiI="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:OKnvXttvCcRZxQicJTqiQpCbFEo=
 by: Kaz Kylheku - Wed, 13 Apr 2022 23:36 UTC

On 2022-04-13, Stefan Ram <ram@zedat.fu-berlin.de> wrote:
> Alan Mackenzie <acm@muc.de> writes:
>>Too many parentheses can make C code difficult to read. Difficult to
>>read translates to "more bugs". A knowledge of C's precedence levels,
>>at least to a moderate degree, can help avoid such bugs.
>
> When I would see an expression such as "( 3 * x )+ t", I might spend
> some time wondering about why the redundant parentheses are there!

Maybe it was copy and pasted from a macro expansion, where 3 * x
had come in as an argument.

Extra parens can help with indentation when an expression
is broken up into multiple lines.

given:

a*b*c*d*... + m*n*o*p* + ...

we might do this at first

a*b*c*d*... +
m*n*o*p*... +
...

the terms of the addition go on separate lines. Now suppose
the terms themselves are too long: now what?

a*b*c*
d*... +
m*n*
o*p*... +
...

that's not very good; extra parens improve it.

(a*b*c*d*...) +
(m*n*o*p*...) +
(...)

then:

(a*b*c*
d*...) +
(m*n*o
*p*...) +
(...)

Chances are your editor will handle this automatically.

Re: Memorizing C operator precedence

<20220413163721.82@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21210&group=comp.lang.c#21210

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Memorizing C operator precedence
Date: Wed, 13 Apr 2022 23:48:30 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <20220413163721.82@kylheku.com>
References: <memo-20220412132213@ram.dialup.fu-berlin.de>
<t34f1f$s4u$1@gioia.aioe.org> <t373kj$1avk$1@news.muc.de>
Injection-Date: Wed, 13 Apr 2022 23:48:30 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="823c5dc8aa629ee253d481526a6b22f4";
logging-data="31349"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+uNSA/OedmCtDoLVOaxCayLFOJAFzINVA="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:XH6tXKYGIZTVC09t51E8u6ogK5s=
 by: Kaz Kylheku - Wed, 13 Apr 2022 23:48 UTC

On 2022-04-13, Alan Mackenzie <acm@muc.de> wrote:
> Jens Stuckelberger <Jens_Stuckelberger@nowhere.net> wrote:
>> On 12 Apr 2022 13:03:39 GMT, Stefan Ram wrote:
>
>>> [...]
>
>> What for? Use parentheses - that's what they are there for.
>
> If you want to use parentheses, you should be writing in Lisp. ;-)

When you write in Lisp, most of the formatting is automatic and almost
always looks good, so you can concentrate on coding.

There are some new developments in this area in the last few years,
like the "parinfer" algorithm. "parinfer" creates a two-way linkage
between indentation and parentheses. Write your code, adjusting
indentation as you go, and the right parentheses materialize
automatically. Or, tweak the parentheses and the indentation fixes
itself accordingly. Google for demos of this.
>
> Too many parentheses can make C code difficult to read. Difficult to
> read translates to "more bugs". A knowledge of C's precedence levels,
> at least to a moderate degree, can help avoid such bugs.

Too much complexity in one expression makes it hard to read. Other
than breaking it up into smaller expression, what can help is to
split it into multiple lines and use indentation.

Parenthesized expressions are much more amenable for splitting across
lines and indenting than pure infix operator expressions.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: Memorizing C operator precedence

<t38tjs$cnl$1@news.muc.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21222&group=comp.lang.c#21222

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!news.karotte.org!news.space.net!news.muc.de!.POSTED.news.muc.de!not-for-mail
From: acm...@muc.de (Alan Mackenzie)
Newsgroups: comp.lang.c
Subject: Re: Memorizing C operator precedence
Date: Thu, 14 Apr 2022 10:38:52 -0000 (UTC)
Organization: muc.de e.V.
Message-ID: <t38tjs$cnl$1@news.muc.de>
References: <memo-20220412132213@ram.dialup.fu-berlin.de> <t34f1f$s4u$1@gioia.aioe.org> <t373kj$1avk$1@news.muc.de> <20220413163721.82@kylheku.com>
Injection-Date: Thu, 14 Apr 2022 10:38:52 -0000 (UTC)
Injection-Info: news.muc.de; posting-host="news.muc.de:2001:608:1000::2";
logging-data="13045"; mail-complaints-to="news-admin@muc.de"
User-Agent: tin/2.4.5-20201224 ("Glen Albyn") (FreeBSD/12.3-RELEASE-p5 (amd64))
 by: Alan Mackenzie - Thu, 14 Apr 2022 10:38 UTC

Kaz Kylheku <480-992-1380@kylheku.com> wrote:
> On 2022-04-13, Alan Mackenzie <acm@muc.de> wrote:
>> Jens Stuckelberger <Jens_Stuckelberger@nowhere.net> wrote:
>>> On 12 Apr 2022 13:03:39 GMT, Stefan Ram wrote:
>>
>>>> [...]

>>> What for? Use parentheses - that's what they are there for.

>> If you want to use parentheses, you should be writing in Lisp. ;-)

> When you write in Lisp, most of the formatting is automatic and almost
> always looks good, so you can concentrate on coding.

Yes.

> There are some new developments in this area in the last few years,
> like the "parinfer" algorithm. "parinfer" creates a two-way linkage
> between indentation and parentheses. Write your code, adjusting
> indentation as you go, and the right parentheses materialize
> automatically. Or, tweak the parentheses and the indentation fixes
> itself accordingly. Google for demos of this.

I think that would drive me crazy!

>> Too many parentheses can make C code difficult to read. Difficult to
>> read translates to "more bugs". A knowledge of C's precedence levels,
>> at least to a moderate degree, can help avoid such bugs.

> Too much complexity in one expression makes it hard to read. Other
> than breaking it up into smaller expression, what can help is to
> split it into multiple lines and use indentation.

This is a common attitude, and I'm sure it is wrong a lot of the time.
Breaking up a complicated expression _fragments_ it - it spreads it over
a greater number of source code lines, some of which may not be visible
on the screen. While each fragment may in itself be easier to read, the
entire expression has become more difficult.

> Parenthesized expressions are much more amenable for splitting across
> lines and indenting than pure infix operator expressions.

I'm not sure I agree with this, my background being the maintainer of
Emacs's CC Mode.

How about a real world example? In the following (from Emacs's
syntax.c):

if (code == Sendcomment
&& SYNTAX_FLAGS_COMMENT_STYLE (syntax, 0) == style
&& (SYNTAX_FLAGS_COMMENT_NESTED (syntax) ?
(nesting > 0 && --nesting == 0) : nesting < 0)
&& !comment_ender_quoted (from, from_byte, syntax))

, which is a moderately complicated example, extra parentheses around
the operands of the &&s would clutter up the code rather than clarifying
it. Yet the whole expression being on just five lines makes it
relatively easy to understand.

> --
> TXR Programming Language: http://nongnu.org/txr
> Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

--
Alan Mackenzie (Nuremberg, Germany).

Re: Memorizing C operator precedence

<t38tm6$hr6$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21223&group=comp.lang.c#21223

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Memorizing C operator precedence
Date: Thu, 14 Apr 2022 12:39:51 +0200
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <t38tm6$hr6$1@dont-email.me>
References: <memo-20220412132213@ram.dialup.fu-berlin.de>
<t34f1f$s4u$1@gioia.aioe.org> <t373kj$1avk$1@news.muc.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 14 Apr 2022 10:40:06 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="da82c5e3da1f645d0b849dae58272e57";
logging-data="18278"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19M45iFpp3+uLht113XO0rbJJuoFYxlGoI="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101
Thunderbird/60.6.1
Cancel-Lock: sha1:kyShA/r6dGXI+Sb8Bhu6Z6S86Lg=
In-Reply-To: <t373kj$1avk$1@news.muc.de>
Content-Language: en-GB
 by: David Brown - Thu, 14 Apr 2022 10:39 UTC

On 13/04/2022 20:09, Alan Mackenzie wrote:
> Jens Stuckelberger <Jens_Stuckelberger@nowhere.net> wrote:
>> On 12 Apr 2022 13:03:39 GMT, Stefan Ram wrote:
>
>>> [...]
>
>> What for? Use parentheses - that's what they are there for.
>
> If you want to use parentheses, you should be writing in Lisp. ;-)
>
> Too many parentheses can make C code difficult to read. Difficult to
> read translates to "more bugs". A knowledge of C's precedence levels,
> at least to a moderate degree, can help avoid such bugs.
>

The challenge with "moderate degree" is that no one can agree where that
lies.

> Maybe some day we'll get the compiler warning "unnecessary parentheses".
>

Or more usefully (IMHO, of course), a warning for overly complicated
expressions that would be better split up. If you are not sure whether
parentheses are necessary or not, or would help some readers and annoy
others, then that's a good clue that separate statements could be a
better arrangement. Local variables are free, after all - mistakes and
misunderstandings are not.

Re: Memorizing C operator precedence

<20220414134305.103@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21239&group=comp.lang.c#21239

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Memorizing C operator precedence
Date: Thu, 14 Apr 2022 21:05:03 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 133
Message-ID: <20220414134305.103@kylheku.com>
References: <memo-20220412132213@ram.dialup.fu-berlin.de>
<t34f1f$s4u$1@gioia.aioe.org> <t373kj$1avk$1@news.muc.de>
<20220413163721.82@kylheku.com> <t38tjs$cnl$1@news.muc.de>
Injection-Date: Thu, 14 Apr 2022 21:05:03 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="823c5dc8aa629ee253d481526a6b22f4";
logging-data="19594"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/JSaGk1EIHdGuI1Co0sKN8UErptf3di1w="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:EVq0r/KXEmccUPyqCMnZP/Jdapg=
 by: Kaz Kylheku - Thu, 14 Apr 2022 21:05 UTC

On 2022-04-14, Alan Mackenzie <acm@muc.de> wrote:
> Kaz Kylheku <480-992-1380@kylheku.com> wrote:
>> On 2022-04-13, Alan Mackenzie <acm@muc.de> wrote:
>>> Jens Stuckelberger <Jens_Stuckelberger@nowhere.net> wrote:
>>>> On 12 Apr 2022 13:03:39 GMT, Stefan Ram wrote:
>>>
>>>>> [...]
>
>>>> What for? Use parentheses - that's what they are there for.
>
>>> If you want to use parentheses, you should be writing in Lisp. ;-)
>
>> When you write in Lisp, most of the formatting is automatic and almost
>> always looks good, so you can concentrate on coding.
>
> Yes.
>
>> There are some new developments in this area in the last few years,
>> like the "parinfer" algorithm. "parinfer" creates a two-way linkage
>> between indentation and parentheses. Write your code, adjusting
>> indentation as you go, and the right parentheses materialize
>> automatically. Or, tweak the parentheses and the indentation fixes
>> itself accordingly. Google for demos of this.
>
> I think that would drive me crazy!
>
>>> Too many parentheses can make C code difficult to read. Difficult to
>>> read translates to "more bugs". A knowledge of C's precedence levels,
>>> at least to a moderate degree, can help avoid such bugs.
>
>> Too much complexity in one expression makes it hard to read. Other
>> than breaking it up into smaller expression, what can help is to
>> split it into multiple lines and use indentation.
>
> This is a common attitude, and I'm sure it is wrong a lot of the time.
> Breaking up a complicated expression _fragments_ it - it spreads it over
> a greater number of source code lines, some of which may not be visible
> on the screen.

A large expression won't be visible all at once, eithery way; if it is on
too few lines, they end up long. If we have multiple choices about
how to break it up, we can achieve a best fit.

> While each fragment may in itself be easier to read, the
> entire expression has become more difficult.
>
>> Parenthesized expressions are much more amenable for splitting across
>> lines and indenting than pure infix operator expressions.
>
> I'm not sure I agree with this, my background being the maintainer of
> Emacs's CC Mode.
>
> How about a real world example? In the following (from Emacs's
> syntax.c):
>
> if (code == Sendcomment
> && SYNTAX_FLAGS_COMMENT_STYLE (syntax, 0) == style
> && (SYNTAX_FLAGS_COMMENT_NESTED (syntax) ?
> (nesting > 0 && --nesting == 0) : nesting < 0)
> && !comment_ender_quoted (from, from_byte, syntax))

Interestingly, you have unnecessary parentheses there, in the ternary:

a ? (b) : c

b is already flanked by a ? opener and : closer. I will keep those,
and for consistency parenthesize the (c) also.

> , which is a moderately complicated example, extra parentheses around
> the operands of the &&s would clutter up the code rather than clarifying
> it. Yet the whole expression being on just five lines makes it
> relatively easy to understand.

Proposal:

if ((code == Sendcomment) &&
(SYNTAX_FLAGS_COMMENT_STYLE (syntax, 0) == style) &&
(SYNTAX_FLAGS_COMMENT_NESTED (syntax)
? (nesting > 0 && --nesting == 0)
: (nesting < 0)) &&
(!comment_ender_quoted (from, from_byte, syntax)))

There is now consistent alignment. When we scan the left edge, we
don't see funny business like:

code ==
(SYNTAX...
SYNTAX..

I find that the infix operators are best put at the end of the previous
line, so that the left edge always begins with an operand, where we can
have a parenthesis for promoting alignment.

This can be visualized in chunks like this:

if ((...................) &&
(...............................................) &&
(....................................
? (.............................)
: (...........)) &&
(!.............................................)))

It is a regret that the && operators are not vertically aligned.

Not knowing quite where to put the infix operators is just the scourge
of infix:

(if (and (eq code 'sendcomment)
(eq (syntax-flags-comment-style syntax 0) 'style)
(if (syntax-flags-comment-nested syntax)
(if (plusp nesting) (zerop (dec nesting)))
(minus nesting))
(not (comment-gender-quoted from from-byte syntax)))
(then-do-this))

No neet to repeat the "and": just write it once and give it arguments.
line by line, indented to the same column.

If we want to be slightly sneaky, we take advantage of and being a
generalization of if:

(and (eq code 'sendcomment)
(eq (syntax-flags-comment-style syntax 0) 'style)
(if (syntax-flags-comment-nested syntax)
(if (plusp nesting) (zerop (dec nesting)))
(minus nesting))
(not (comment-gender-quoted from from-byte syntax))
(then-do-this))

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: Memorizing C operator precedence

<extract-variable-20220415185849@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21246&group=comp.lang.c#21246

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.c
Subject: Re: Memorizing C operator precedence
Date: 15 Apr 2022 18:00:22 GMT
Organization: Stefan Ram
Lines: 28
Expires: 1 Apr 2023 11:59:58 GMT
Message-ID: <extract-variable-20220415185849@ram.dialup.fu-berlin.de>
References: <memo-20220412132213@ram.dialup.fu-berlin.de> <t34f1f$s4u$1@gioia.aioe.org> <t373kj$1avk$1@news.muc.de> <20220413163721.82@kylheku.com> <t38tjs$cnl$1@news.muc.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 5Y1nZGQhdawCmlKbCUFr7gIPDlZekOBFYKP76PgHeLFgxV
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Fri, 15 Apr 2022 18:00 UTC

Alan Mackenzie <acm@muc.de> writes:
>Breaking up a complicated expression _fragments_ it

Example for the refactor "extract variable" in pseudocode:

return quantity * item_price -
max(0, quantity - 500) * item_price * 0.05 +
min(quantity * item_price * 0.1, 100);

------------------>

const base_price = quantity * item_price;
const quantity_discount =
max( 0, quantity - 500 )* item_price * 0.05;
const shipping = min( base_price * 0.1, 100 );
return base_price - quantity_discount + shipping;

. There is no reason to fall behind the state of the art.
Suggested reading:

Refactoring - Improving the Design of Existing Code
by Martin Fowler,
publishing house Addison-Wesley Educational Publishers Inc.

. Don't worry! It is written in an easy-to-understand way
so that most programmers can get it.

Re: Memorizing C operator precedence

<t3ejp3$2ch3$1@news.muc.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21250&group=comp.lang.c#21250

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news-peer.in.tum.de!news.muc.de!.POSTED.news.muc.de!not-for-mail
From: acm...@muc.de (Alan Mackenzie)
Newsgroups: comp.lang.c
Subject: Re: Memorizing C operator precedence
Date: Sat, 16 Apr 2022 14:27:47 -0000 (UTC)
Organization: muc.de e.V.
Message-ID: <t3ejp3$2ch3$1@news.muc.de>
References: <memo-20220412132213@ram.dialup.fu-berlin.de> <t34f1f$s4u$1@gioia.aioe.org> <t373kj$1avk$1@news.muc.de> <20220413163721.82@kylheku.com> <t38tjs$cnl$1@news.muc.de> <extract-variable-20220415185849@ram.dialup.fu-berlin.de>
Injection-Date: Sat, 16 Apr 2022 14:27:47 -0000 (UTC)
Injection-Info: news.muc.de; posting-host="news.muc.de:2001:608:1000::2";
logging-data="78371"; mail-complaints-to="news-admin@muc.de"
User-Agent: tin/2.4.5-20201224 ("Glen Albyn") (FreeBSD/12.3-RELEASE-p5 (amd64))
 by: Alan Mackenzie - Sat, 16 Apr 2022 14:27 UTC

Stefan Ram <ram@zedat.fu-berlin.de> wrote:
> Alan Mackenzie <acm@muc.de> writes:
>>Breaking up a complicated expression _fragments_ it

> Example for the refactor "extract variable" in pseudocode:

> return quantity * item_price -
> max(0, quantity - 500) * item_price * 0.05 +
> min(quantity * item_price * 0.1, 100);

> ------------------>

> const base_price = quantity * item_price;
> const quantity_discount =
> max( 0, quantity - 500 )* item_price * 0.05;
> const shipping = min( base_price * 0.1, 100 );
> return base_price - quantity_discount + shipping;

> . There is no reason to fall behind the state of the art.

Whatever that might be in this particular matter. In your rearrangement
of code, you have doubled its size. You have increased the number of
operators used from 8 to 10, the number of lines of code from 3 to 5 and
the number of statements from 1 to 4.

Other things being equal, a more concise expression is easier to
understand. No doubt you would here argue that the other things aren't
equal, and I agree there is some merit to that argument.

But the 5-line version is primarily easier for beginners to understand,
who mentally break down program text to smaller units. An experienced
programmer will prefer the 1-statement version - on encountering the
4-statement version she will subconsciously remark "do I have to go
through all this verbiage _again_?".

> Suggested reading:

> Refactoring - Improving the Design of Existing Code
> by Martin Fowler,
> publishing house Addison-Wesley Educational Publishers Inc.

> . Don't worry! It is written in an easy-to-understand way
> so that most programmers can get it.

No worries! I've had a copy of this book for many years, though it's
some time since I've read it. Just because one can refactor code doesn't
mean it's necessarily a good thing to do. Often it is. I think it was
Steve Yegge in one of his blogs who noted that the problem with
refactoring is that it often bloats code size.

--
Alan Mackenzie (Nuremberg, Germany).

Re: Memorizing C operator precedence

<t3ejs8$1mek$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21251&group=comp.lang.c#21251

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!YgKMkT8Hbhw8vNatTmzQ/w.user.46.165.242.75.POSTED!not-for-mail
From: the.ha...@gmail.com (Christian Hanné)
Newsgroups: comp.lang.c
Subject: Re: Memorizing C operator precedence
Date: Sat, 16 Apr 2022 16:29:40 +0200
Organization: Aioe.org NNTP Server
Message-ID: <t3ejs8$1mek$1@gioia.aioe.org>
References: <memo-20220412132213@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="55764"; posting-host="YgKMkT8Hbhw8vNatTmzQ/w.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.8.0
Content-Language: de-DE
X-Notice: Filtered by postfilter v. 0.9.2
 by: Christian Hanné - Sat, 16 Apr 2022 14:29 UTC

Better use a language like C++17 and further where you can redfine
the operator precedence.

Re: Memorizing C operator precedence

<t3esqh$1s6g$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21252&group=comp.lang.c#21252

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!Ii/B5BhfUNgTvoakw4dy9Q.user.46.165.242.75.POSTED!not-for-mail
From: mess...@bottle.org (Guillaume)
Newsgroups: comp.lang.c
Subject: Re: Memorizing C operator precedence
Date: Sat, 16 Apr 2022 19:02:03 +0200
Organization: Aioe.org NNTP Server
Message-ID: <t3esqh$1s6g$1@gioia.aioe.org>
References: <memo-20220412132213@ram.dialup.fu-berlin.de>
<t3ejs8$1mek$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="61648"; posting-host="Ii/B5BhfUNgTvoakw4dy9Q.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.8.0
Content-Language: fr
X-Notice: Filtered by postfilter v. 0.9.2
 by: Guillaume - Sat, 16 Apr 2022 17:02 UTC

Le 16/04/2022 à 16:29, Christian Hanné a écrit :
> Better use a language like C++17 and further where you can redfine
> the operator precedence.

What a nice idea.

Re: Memorizing C operator precedence

<20220416104034.730@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21253&group=comp.lang.c#21253

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!paganini.bofh.team!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Memorizing C operator precedence
Date: Sat, 16 Apr 2022 17:43:31 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <20220416104034.730@kylheku.com>
References: <memo-20220412132213@ram.dialup.fu-berlin.de>
<t3ejs8$1mek$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 16 Apr 2022 17:43:31 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ab67a14ff01771b1ef650959bb84d379";
logging-data="24807"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+axjEyA4vv5enT9/KRFOTne41S8dQ3Eg0="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:tgUB7NlCfC6e/ozmILisD5nsock=
 by: Kaz Kylheku - Sat, 16 Apr 2022 17:43 UTC

On 2022-04-16, Christian Hanné <the.hanne@gmail.com> wrote:
> Better use a language like C++17 and further where you can redfine
> the operator precedence.

Please cite chapter and verse in the C++17 standrad and provide
a minimal sample.

Or else, please FOAD. If you don't know what that means, refer to:

ISO/IEC 2382−1:1993, Information technology — Vocabulary — Part 1: Fundamental
terms.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: Memorizing C operator precedence

<t3f0vv$30qhr$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21254&group=comp.lang.c#21254

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.c
Subject: Re: Memorizing C operator precedence
Date: Sat, 16 Apr 2022 18:13:19 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <t3f0vv$30qhr$1@news.xmission.com>
References: <memo-20220412132213@ram.dialup.fu-berlin.de> <t3ejs8$1mek$1@gioia.aioe.org> <20220416104034.730@kylheku.com>
Injection-Date: Sat, 16 Apr 2022 18:13:19 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="3172923"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Sat, 16 Apr 2022 18:13 UTC

In article <20220416104034.730@kylheku.com>,
Kaz Kylheku <480-992-1380@kylheku.com> wrote:
>On 2022-04-16, Christian Hann <the.hanne@gmail.com> wrote:
>> Better use a language like C++17 and further where you can redfine
>> the operator precedence.
>
>Please cite chapter and verse in the C++17 standrad and provide
>a minimal sample.

Maybe he has his own, customized version of C++.

Just like both of us - you and me - have our own, customized versions of
GAWK. Which are pretty much inaccessible to the rest of the world, and all
they can do is look on from afar, with a combined sense of wonder and awe,
with a not insignificant dollop of envy as well.

--
I voted for Trump because I thought he'd make pussy grabbing legal.
I honestly don't see any other way America could be made great again.

Re: Memorizing C operator precedence

<87ee1welr5.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21256&group=comp.lang.c#21256

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Memorizing C operator precedence
Date: Sat, 16 Apr 2022 14:55:42 -0700
Organization: None to speak of
Lines: 14
Message-ID: <87ee1welr5.fsf@nosuchdomain.example.com>
References: <memo-20220412132213@ram.dialup.fu-berlin.de>
<t3ejs8$1mek$1@gioia.aioe.org> <t3esqh$1s6g$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="3725248eb51eaf4c8ed29483282c97d4";
logging-data="772"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18LXhicDUVmfRQ8/Kb3HYl8"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:JoSgKTZQUuGVE6d7RsfQxVU9qRY=
sha1:sCM3zuIN6GBiCYmPAYThFenozLg=
 by: Keith Thompson - Sat, 16 Apr 2022 21:55 UTC

Guillaume <message@bottle.org> writes:
> Le 16/04/2022 à 16:29, Christian Hanné a écrit :
>> Better use a language like C++17 and further where you can redfine
>> the operator precedence.
>
> What a nice idea.

C++17 does not allow redefinition of operator precedence. Christian
Hanné is a lying troll.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: Memorizing C operator precedence

<20220417203420.179@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21259&group=comp.lang.c#21259

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Memorizing C operator precedence
Date: Mon, 18 Apr 2022 03:43:03 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <20220417203420.179@kylheku.com>
References: <memo-20220412132213@ram.dialup.fu-berlin.de>
<t3ejs8$1mek$1@gioia.aioe.org> <20220416104034.730@kylheku.com>
<t3f0vv$30qhr$1@news.xmission.com>
Injection-Date: Mon, 18 Apr 2022 03:43:03 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="6aab72b3d451db54ac71f617edd25812";
logging-data="17312"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18h/8C7jKIrAF1O4E6vEOo7MSHn4MfLmpM="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:Xqz5zZj4IEo/7AQM9REH7p2ALOE=
 by: Kaz Kylheku - Mon, 18 Apr 2022 03:43 UTC

On 2022-04-16, Kenny McCormack <gazelle@shell.xmission.com> wrote:
> In article <20220416104034.730@kylheku.com>,
> Kaz Kylheku <480-992-1380@kylheku.com> wrote:
>>On 2022-04-16, Christian Hann <the.hanne@gmail.com> wrote:
>>> Better use a language like C++17 and further where you can redfine
>>> the operator precedence.
>>
>>Please cite chapter and verse in the C++17 standrad and provide
>>a minimal sample.
>
> Maybe he has his own, customized version of C++.
>
> Just like both of us - you and me - have our own, customized versions of
> GAWK. Which are pretty much inaccessible to the rest of the world, and all
> they can do is look on from afar, with a combined sense of wonder and awe,
> with a not insignificant dollop of envy as well.

I'm not sure what you mean by "accessible". I /very/ recently started a
small feature fork of GNU Awk, as in within this past week. It is
publicly hosted, and has updated documentation and test cases. Now it's
not "accessible" the way upstream Gawk is accessible whereby you can
just do "apt-get install gawk" at your Ubuntu prompt, and it's not (yet)
even accessible in the way that you can pull down a gawk-x.y.z.tar.xz
ball, unpack it and build it without needing Automake and Autoconf and
all that (which I will in due time). But it's not "inaccessible".

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: Memorizing C operator precedence

<6295432d-6ca9-49ea-b29c-858de4b65b75n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21416&group=comp.lang.c#21416

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:2aa2:b0:446:66a7:49b3 with SMTP id js2-20020a0562142aa200b0044666a749b3mr7732833qvb.7.1650734625968;
Sat, 23 Apr 2022 10:23:45 -0700 (PDT)
X-Received: by 2002:a05:6214:212c:b0:443:cacc:ee8 with SMTP id
r12-20020a056214212c00b00443cacc0ee8mr7519811qvc.96.1650734625863; Sat, 23
Apr 2022 10:23:45 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sat, 23 Apr 2022 10:23:45 -0700 (PDT)
In-Reply-To: <t3ejp3$2ch3$1@news.muc.de>
Injection-Info: google-groups.googlegroups.com; posting-host=89.240.149.86; posting-account=0B-afgoAAABP6274zLUJKa8ZpdIdhsYx
NNTP-Posting-Host: 89.240.149.86
References: <memo-20220412132213@ram.dialup.fu-berlin.de> <t34f1f$s4u$1@gioia.aioe.org>
<t373kj$1avk$1@news.muc.de> <20220413163721.82@kylheku.com>
<t38tjs$cnl$1@news.muc.de> <extract-variable-20220415185849@ram.dialup.fu-berlin.de>
<t3ejp3$2ch3$1@news.muc.de>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6295432d-6ca9-49ea-b29c-858de4b65b75n@googlegroups.com>
Subject: Re: Memorizing C operator precedence
From: gw7...@aol.com (Paul N)
Injection-Date: Sat, 23 Apr 2022 17:23:45 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 22
 by: Paul N - Sat, 23 Apr 2022 17:23 UTC

On Saturday, April 16, 2022 at 3:28:00 PM UTC+1, Alan Mackenzie wrote:
> Stefan Ram <r...@zedat.fu-berlin.de> wrote:
> > Alan Mackenzie <a...@muc.de> writes:
> >>Breaking up a complicated expression _fragments_ it
> > Example for the refactor "extract variable" in pseudocode:
>
> > return quantity * item_price -
> > max(0, quantity - 500) * item_price * 0.05 +
> > min(quantity * item_price * 0.1, 100);
>
> > ------------------>
>
> > const base_price = quantity * item_price;
> > const quantity_discount =
> > max( 0, quantity - 500 )* item_price * 0.05;
> > const shipping = min( base_price * 0.1, 100 );
> > return base_price - quantity_discount + shipping;

How about a compromise?

return quantity * item_price
- max(0, quantity - 500) * item_price * 0.05 // quantity discount
+ min(quantity * item_price * 0.1, 100); // shipping

Re: Memorizing C operator precedence

<t45sne$2r7r$1@news.muc.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21453&group=comp.lang.c#21453

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news-peer.in.tum.de!news.muc.de!.POSTED.news.muc.de!not-for-mail
From: acm...@muc.de (Alan Mackenzie)
Newsgroups: comp.lang.c
Subject: Re: Memorizing C operator precedence
Date: Mon, 25 Apr 2022 10:21:34 -0000 (UTC)
Organization: muc.de e.V.
Message-ID: <t45sne$2r7r$1@news.muc.de>
References: <memo-20220412132213@ram.dialup.fu-berlin.de> <t34f1f$s4u$1@gioia.aioe.org> <t373kj$1avk$1@news.muc.de> <20220413163721.82@kylheku.com> <t38tjs$cnl$1@news.muc.de> <extract-variable-20220415185849@ram.dialup.fu-berlin.de> <t3ejp3$2ch3$1@news.muc.de> <6295432d-6ca9-49ea-b29c-858de4b65b75n@googlegroups.com>
Injection-Date: Mon, 25 Apr 2022 10:21:34 -0000 (UTC)
Injection-Info: news.muc.de; posting-host="news.muc.de:2001:608:1000::2";
logging-data="93435"; mail-complaints-to="news-admin@muc.de"
User-Agent: tin/2.4.5-20201224 ("Glen Albyn") (FreeBSD/12.3-RELEASE-p5 (amd64))
 by: Alan Mackenzie - Mon, 25 Apr 2022 10:21 UTC

Paul N <gw7rib@aol.com> wrote:
> On Saturday, April 16, 2022 at 3:28:00 PM UTC+1, Alan Mackenzie wrote:
>> Stefan Ram <r...@zedat.fu-berlin.de> wrote:
>> > Alan Mackenzie <a...@muc.de> writes:
>> >>Breaking up a complicated expression _fragments_ it
>> > Example for the refactor "extract variable" in pseudocode:

>> > return quantity * item_price -
>> > max(0, quantity - 500) * item_price * 0.05 +
>> > min(quantity * item_price * 0.1, 100);

>> > ------------------>

>> > const base_price = quantity * item_price;
>> > const quantity_discount =
>> > max( 0, quantity - 500 )* item_price * 0.05;
>> > const shipping = min( base_price * 0.1, 100 );
>> > return base_price - quantity_discount + shipping;

> How about a compromise?

> return quantity * item_price
> - max(0, quantity - 500) * item_price * 0.05 // quantity discount
> + min(quantity * item_price * 0.1, 100); // shipping

I think that is the best of all! Inserting brief, meaningful comments,
as above, makes the thing easy to understand without bloating the code.
I wish more people would code like this.

--
Alan Mackenzie (Nuremberg, Germany).

Re: Memorizing C operator precedence

<t46fih$qkr$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21458&group=comp.lang.c#21458

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: vir.camp...@invalid.invalid (Vir Campestris)
Newsgroups: comp.lang.c
Subject: Re: Memorizing C operator precedence
Date: Mon, 25 Apr 2022 16:43:13 +0100
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <t46fih$qkr$1@dont-email.me>
References: <memo-20220412132213@ram.dialup.fu-berlin.de>
<t34f1f$s4u$1@gioia.aioe.org> <t373kj$1avk$1@news.muc.de>
<20220413163721.82@kylheku.com> <t38tjs$cnl$1@news.muc.de>
<extract-variable-20220415185849@ram.dialup.fu-berlin.de>
<t3ejp3$2ch3$1@news.muc.de>
<6295432d-6ca9-49ea-b29c-858de4b65b75n@googlegroups.com>
<t45sne$2r7r$1@news.muc.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 25 Apr 2022 15:43:13 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d2be5c016d3ff20943ecb39977e0ff68";
logging-data="27291"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18oyNkOhUA7pF7sdXgoZq5yOk8GGgnrowY="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Cancel-Lock: sha1:LiyLyLA9N+nGjekp3qvX/AYTSJc=
In-Reply-To: <t45sne$2r7r$1@news.muc.de>
Content-Language: en-GB
 by: Vir Campestris - Mon, 25 Apr 2022 15:43 UTC

On 25/04/2022 11:21, Alan Mackenzie wrote:
> I think that is the best of all! Inserting brief, meaningful comments,
> as above, makes the thing easy to understand without bloating the code.
> I wish more people would code like this.

Absolutely.

It has the great advantage that the comments say what the code is
_supposed_ to do. If they disagree that's a great big alarm bell to
anyone looking for bugs.

"self documenting code" doesn't do that.

Andy

Re: Memorizing C operator precedence

<86pml46dhb.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21471&group=comp.lang.c#21471

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Memorizing C operator precedence
Date: Mon, 25 Apr 2022 14:48:48 -0700
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <86pml46dhb.fsf@linuxsc.com>
References: <memo-20220412132213@ram.dialup.fu-berlin.de> <t34f1f$s4u$1@gioia.aioe.org> <t373kj$1avk$1@news.muc.de> <20220413163721.82@kylheku.com> <t38tjs$cnl$1@news.muc.de> <extract-variable-20220415185849@ram.dialup.fu-berlin.de> <t3ejp3$2ch3$1@news.muc.de> <6295432d-6ca9-49ea-b29c-858de4b65b75n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="2b2bd3060d7fb14ae545fc6b32585799";
logging-data="7476"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX189xLGD73fKQK6WgxtErLVoLKoz2UMjmKE="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:vcaxcr9sdOURJElBPYxsRD+cZqE=
sha1:Y+04RcK9jjj6lIQKwonD1BAX0vo=
 by: Tim Rentsch - Mon, 25 Apr 2022 21:48 UTC

Paul N <gw7rib@aol.com> writes:

> On Saturday, April 16, 2022 at 3:28:00 PM UTC+1, Alan Mackenzie wrote:
>
>> Stefan Ram <r...@zedat.fu-berlin.de> wrote:
>>
>>> Alan Mackenzie <a...@muc.de> writes:
>>>
>>>> Breaking up a complicated expression _fragments_ it
>>>
>>> Example for the refactor "extract variable" in pseudocode:
>>>
>>> return quantity * item_price -
>>> max(0, quantity - 500) * item_price * 0.05 +
>>> min(quantity * item_price * 0.1, 100);
>>>
>>> ------------------>
>>>
>>> const base_price = quantity * item_price;
>>> const quantity_discount =
>>> max( 0, quantity - 500 )* item_price * 0.05;
>>> const shipping = min( base_price * 0.1, 100 );
>>> return base_price - quantity_discount + shipping;
>
> How about a compromise?
>
> return quantity * item_price
> - max(0, quantity - 500) * item_price * 0.05 // quantity discount
> + min(quantity * item_price * 0.1, 100); // shipping

Speaking for myself I would rather see something like this:

[...]
unsigned n = quantity;
double price = item_price;
return sale_charge( n, price ) + shipping_charge( n, price );

double
sale_charge( unsigned n, double price ){
return base_charge( n, price ) - quantity_discount( n, price );
}

double
shipping_charge( unsigned n, double price ){
return min( base_charge( n, price ) * 0.1, 100.0 );
}

double
base_charge( unsigned n, double price ){
return n * price;
}

double
quantity_discount( unsigned n, double price ){
return n > 500 ? (n-500) * price * 0.05 : 0;
}

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor