Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

You can observe a lot just by watching. -- Yogi Berra


devel / comp.lang.c / Operator Precedence

SubjectAuthor
* Operator PrecedenceLawrence D'Oliveiro
+* Re: Operator PrecedenceMalcolm McLean
|`* Re: Operator PrecedenceLawrence D'Oliveiro
| +* Re: Operator PrecedenceKeith Thompson
| |`* Re: Operator PrecedenceLawrence D'Oliveiro
| | +- Re: Operator PrecedenceKaz Kylheku
| | `- Re: Operator PrecedenceDavid Brown
| `* Re: Operator PrecedenceLew Pitcher
|  `* Re: Operator PrecedenceLawrence D'Oliveiro
|   `- Re: Operator PrecedenceLew Pitcher
+- Re: Operator PrecedenceKaz Kylheku
`- Re: Operator PrecedenceTim Rentsch

1
Operator Precedence

<ups1ok$h6mt$6@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo...@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.c
Subject: Operator Precedence
Date: Tue, 6 Feb 2024 01:24:36 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <ups1ok$h6mt$6@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 6 Feb 2024 01:24:36 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="06aca01f94cf0cf48b148884bafbedb9";
logging-data="563933"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+CYL0omaq5ZxPf+31Jk5HH"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:L1habjDHLKScT8WTp++dq/lJ590=
 by: Lawrence D'Oliv - Tue, 6 Feb 2024 01:24 UTC

Operator precedence in C, particularly in regard to the bitwise operators,
can be a bit awkward. Consider an expression like

(val & check_bits) == set_bits

which uses “check_bits” to mask out the bits to check from “val”, and then
compares the result to “set_bits”. A more natural precedence order would
allow this to be written without the parentheses:

val & check_bits == set_bits

I discovered a few years ago (quite by accident) that Python does make a
small change to the operator precedences to allow exactly this sort of
thing.

My question is, if this corresponding operator precedence change were to
be made in C, is there any actual real-world code that would break?

Re: Operator Precedence

<ups2hi$hfak$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: malcolm....@gmail.com (Malcolm McLean)
Newsgroups: comp.lang.c
Subject: Re: Operator Precedence
Date: Tue, 6 Feb 2024 01:37:54 +0000
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <ups2hi$hfak$1@dont-email.me>
References: <ups1ok$h6mt$6@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 6 Feb 2024 01:37:54 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="121546b46b87f698889c92479e4b6ace";
logging-data="572756"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+oo4luafpCaZhqGtFqWk/csa77xZPutYU="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:2v86BeJhONBcldUsJx9LCo4W5xI=
Content-Language: en-GB
In-Reply-To: <ups1ok$h6mt$6@dont-email.me>
 by: Malcolm McLean - Tue, 6 Feb 2024 01:37 UTC

On 06/02/2024 01:24, Lawrence D'Oliveiro wrote:
> Operator precedence in C, particularly in regard to the bitwise operators,
> can be a bit awkward. Consider an expression like
>
> (val & check_bits) == set_bits
>
> which uses “check_bits” to mask out the bits to check from “val”, and then
> compares the result to “set_bits”. A more natural precedence order would
> allow this to be written without the parentheses:
>
> val & check_bits == set_bits
>
> I discovered a few years ago (quite by accident) that Python does make a
> small change to the operator precedences to allow exactly this sort of
> thing.
>
> My question is, if this corresponding operator precedence change were to
> be made in C, is there any actual real-world code that would break?

Yes tons of it. Badly written code because in any sensible coding
standard you must have the parentheses. But lots of code like that is
written because it works and, hey, you assume your reader knows C.

It's a bit hard to produce an example at the drop of a hat on demand,
but I read alot of C code and you do come across this sort of thing all
of the time.
--
Check out Basic Algorithms and my other books:
https://www.lulu.com/spotlight/bgy1mm

Re: Operator Precedence

<20240205174950.475@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Operator Precedence
Date: Tue, 6 Feb 2024 02:01:56 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 60
Message-ID: <20240205174950.475@kylheku.com>
References: <ups1ok$h6mt$6@dont-email.me>
Injection-Date: Tue, 6 Feb 2024 02:01:56 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="a112f49d5e72d19646dc68722a58d18c";
logging-data="580349"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18kcy13mSEw6ixcYl5FP+H+IFQ3yZMgTSU="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:M9auivm2uhWc+e/ePlbY1UlC45M=
 by: Kaz Kylheku - Tue, 6 Feb 2024 02:01 UTC

On 2024-02-06, Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
> Operator precedence in C, particularly in regard to the bitwise operators,
> can be a bit awkward. Consider an expression like
>
> (val & check_bits) == set_bits

Yes, this is famous. It's because the bitwise & was used for combining
Boolean conditions, before && was introduced:

if (foo > 0 & odd(bar)) { ... }

In a 1982 e-mail, Dennis Ritchie wrote:

"In retrospect it would have been better to go ahead and change the
precedence of & to higher than ==, but it seemed safer just to split &
and && without moving & past an existing operator. (After all, we had
several hundred kilobytes of source code, and maybe 3 installations....)"

That's it. 600 kilobytes of code being preserved is why we can't have

val & check_bits == set_bits

and whatnot.

> My question is, if this corresponding operator precedence change were to
> be made in C, is there any actual real-world code that would break?

Yes; anything that does

some_condition & variable == TEST_VALUE

where && could have been used, but wasn't. Perhaps due to a typo;
but the code is tested and works since some_condition has the values
0 and 1.

A good time to fix it was when Dennis Ritchie and gang had 600 kilobytes
of code in 3 installations.

Yet, I think the situation could be repaired with a carefully
rolled-out plan.

Firstly, require all ambiguous uses of & to be parenthesized, so
that code like condition & variable == TEST_VALUE requires a diagnostic;
it has to be condition & (variable == TEST_VALUE) or
(condition & variable) == TEST_VALUE.

Then after a long period of obsolescence, remove the requirement for
parentheses, and introduce the new precedence for & and |.

By the time the obsolescence period is over, most old code still in use
would have been fixed to have the required parentheses. Those are now
optional; new code can start using the nicer new precedence.

Then any remaining broken old code can still be supported with old
dialect modes, like "gcc -std=c17" or lower.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Operator Precedence

<ups5cs$hs4o$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo...@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.c
Subject: Re: Operator Precedence
Date: Tue, 6 Feb 2024 02:26:36 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <ups5cs$hs4o$1@dont-email.me>
References: <ups1ok$h6mt$6@dont-email.me> <ups2hi$hfak$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 6 Feb 2024 02:26:36 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="06aca01f94cf0cf48b148884bafbedb9";
logging-data="585880"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18B43Y/6QHkS0ZTOUGdFTnL"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:bo8byrLWf3aG3yiNLoVxWgghtwI=
 by: Lawrence D'Oliv - Tue, 6 Feb 2024 02:26 UTC

On Tue, 6 Feb 2024 01:37:54 +0000, Malcolm McLean wrote:

> On 06/02/2024 01:24, Lawrence D'Oliveiro wrote:
>
>> My question is, if this corresponding operator precedence change were
to
>> be made in C, is there any actual real-world code that would break?
>
> Yes tons of it. Badly written code because in any sensible coding
> standard you must have the parentheses.

Given that everybody has to write it with the parentheses in existing
code, changing the operator precedence will not affect the correctness of
such expressions.

Re: Operator Precedence

<874jemjp7v.fsf@nosuchdomain.example.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Operator Precedence
Date: Mon, 05 Feb 2024 18:33:56 -0800
Organization: None to speak of
Lines: 28
Message-ID: <874jemjp7v.fsf@nosuchdomain.example.com>
References: <ups1ok$h6mt$6@dont-email.me> <ups2hi$hfak$1@dont-email.me>
<ups5cs$hs4o$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="4718b0a0ab2e3c1c2260eb363d68ae7d";
logging-data="587468"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+FwuMsSnM21MYL7j8wOd6u"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:JdRg4pcV7b0onk0z58yaR4DHPzM=
sha1:QkBIDIF/x7RgCeW1DiQCXE1a9fk=
 by: Keith Thompson - Tue, 6 Feb 2024 02:33 UTC

Lawrence D'Oliveiro <ldo@nz.invalid> writes:
> On Tue, 6 Feb 2024 01:37:54 +0000, Malcolm McLean wrote:
>
>> On 06/02/2024 01:24, Lawrence D'Oliveiro wrote:
>>
>>> My question is, if this corresponding operator precedence change were
> to
>>> be made in C, is there any actual real-world code that would break?
>>
>> Yes tons of it. Badly written code because in any sensible coding
>> standard you must have the parentheses.
>
> Given that everybody has to write it with the parentheses in existing
> code, changing the operator precedence will not affect the correctness of
> such expressions.

But not everyone does write it with the parentheses. Taking advantage
of some of the more arcane precedence rules might be uncommon, but it
does happen.

If there were a decision to change the precedence rules in some future
standard, compilers could start warning about code whose meaning would
change in the transition. (Alas, it's far too common to ignore warnings.)

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

Re: Operator Precedence

<ups716$i2ic$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!newsfeed.endofthelinebbs.com!news.hispagatos.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo...@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.c
Subject: Re: Operator Precedence
Date: Tue, 6 Feb 2024 02:54:31 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <ups716$i2ic$1@dont-email.me>
References: <ups1ok$h6mt$6@dont-email.me> <ups2hi$hfak$1@dont-email.me>
<ups5cs$hs4o$1@dont-email.me> <874jemjp7v.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 6 Feb 2024 02:54:31 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="06aca01f94cf0cf48b148884bafbedb9";
logging-data="592460"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+6wYT3JPbjsqY8OI6Ohwoe"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:rSn9Dat4PdMzBHFSmJnUdT1ukVA=
 by: Lawrence D'Oliv - Tue, 6 Feb 2024 02:54 UTC

On Mon, 05 Feb 2024 18:33:56 -0800, Keith Thompson wrote:

> But not everyone does write it with the parentheses.

Let us be clear about what we are talking about. You are suggesting that
people write an expression like

a «bitop» b «cmp» c

with the expectation that it means

a «bitop» (b «cmp» c)

because currently in C, anybody who wants it to mean

(a «bitop» b) «cmp» c

has to write it that way, with explicit parentheses, anyway.

The question is, who would write something like (with or without
parentheses)

a «bitop» (b «cmp» c)

and why? Because a comparison in C only returns either 0 or 1, while bit
operators are most useful dealing with multibit masks.

Re: Operator Precedence

<20240205185640.231@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Operator Precedence
Date: Tue, 6 Feb 2024 02:58:51 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <20240205185640.231@kylheku.com>
References: <ups1ok$h6mt$6@dont-email.me> <ups2hi$hfak$1@dont-email.me>
<ups5cs$hs4o$1@dont-email.me> <874jemjp7v.fsf@nosuchdomain.example.com>
<ups716$i2ic$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 6 Feb 2024 02:58:51 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="a112f49d5e72d19646dc68722a58d18c";
logging-data="593002"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18t7BEkkERvu3rDxwKGLc/ocVAqla/g9DI="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:Ndd7CdjhVLLni/CdFTGl/vwLT2k=
 by: Kaz Kylheku - Tue, 6 Feb 2024 02:58 UTC

On 2024-02-06, Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
> On Mon, 05 Feb 2024 18:33:56 -0800, Keith Thompson wrote:
>
>> But not everyone does write it with the parentheses.
>
> Let us be clear about what we are talking about. You are suggesting that
> people write an expression like
>
> a «bitop» b «cmp» c
>
> with the expectation that it means
>
> a «bitop» (b «cmp» c)

The problem is that this is what it means that regardless of anyone's
expectation.

> The question is, who would write something like (with or without
> parentheses)
>
> a «bitop» (b «cmp» c)

For one thing, someone who writes & instead of &&, or | instead of ||,
as a pure typo, and the operands happen to be in the {0, 1} domain so
that it works fine.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Operator Precedence

<ups7du$hsh9$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.lang.c
Subject: Re: Operator Precedence
Date: Tue, 6 Feb 2024 03:01:18 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <ups7du$hsh9$1@dont-email.me>
References: <ups1ok$h6mt$6@dont-email.me> <ups2hi$hfak$1@dont-email.me>
<ups5cs$hs4o$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 6 Feb 2024 03:01:18 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e6a07a32e0c2f15274a42ec89675d32e";
logging-data="586281"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18LnnOqLtKOGUvUBIHaLlR7ATLFTLsF0H4="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:YzOgLvaDZhDanW2zDkFY2k0OQAU=
 by: Lew Pitcher - Tue, 6 Feb 2024 03:01 UTC

On Tue, 06 Feb 2024 02:26:36 +0000, Lawrence D'Oliveiro wrote:

> On Tue, 6 Feb 2024 01:37:54 +0000, Malcolm McLean wrote:
>
>> On 06/02/2024 01:24, Lawrence D'Oliveiro wrote:
>>
>>> My question is, if this corresponding operator precedence change were
> to
>>> be made in C, is there any actual real-world code that would break?
>>
>> Yes tons of it. Badly written code because in any sensible coding
>> standard you must have the parentheses.
>
> Given that everybody has to write it with the parentheses in existing
> code, changing the operator precedence will not affect the correctness of
> such expressions.

Given that
>>> v_a & v_b == v_c
is a valid expression that binary ANDs v_a with the truth value of the
expression (v_b == v_c), your proposed change in operator precedence would
greatly affect the correctness of the expression.

--
Lew Pitcher
"In Skills We Trust"

Re: Operator Precedence

<ups7m4$i2ic$3@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo...@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.c
Subject: Re: Operator Precedence
Date: Tue, 6 Feb 2024 03:05:40 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <ups7m4$i2ic$3@dont-email.me>
References: <ups1ok$h6mt$6@dont-email.me> <ups2hi$hfak$1@dont-email.me>
<ups5cs$hs4o$1@dont-email.me> <ups7du$hsh9$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 6 Feb 2024 03:05:40 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="06aca01f94cf0cf48b148884bafbedb9";
logging-data="592460"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/RgtRinYeEkwmOBmKJnTMI"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:wix32bnYpRgy8afZK3v/OmXJ2HY=
 by: Lawrence D'Oliv - Tue, 6 Feb 2024 03:05 UTC

On Tue, 6 Feb 2024 03:01:18 -0000 (UTC), Lew Pitcher wrote:

> Given that
>>>> v_a & v_b == v_c
> is a valid expression that binary ANDs v_a with the truth value of the
> expression (v_b == v_c), your proposed change in operator precedence
> would greatly affect the correctness of the expression.

That’s why I asked for “real-world” examples. Why would anyone want to
write such an expression with the bitwise operators, instead of using the
boolean ones?

Re: Operator Precedence

<upsdno$mo7o$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.lang.c
Subject: Re: Operator Precedence
Date: Tue, 6 Feb 2024 04:48:56 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <upsdno$mo7o$1@dont-email.me>
References: <ups1ok$h6mt$6@dont-email.me> <ups2hi$hfak$1@dont-email.me>
<ups5cs$hs4o$1@dont-email.me> <ups7du$hsh9$1@dont-email.me>
<ups7m4$i2ic$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 6 Feb 2024 04:48:56 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e6a07a32e0c2f15274a42ec89675d32e";
logging-data="745720"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19igF4ay9DphTHEqDlOQZkTU67jljr9wUk="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:VIPGJ5ZJ6AvyyD5YPmnFXOKYsNI=
 by: Lew Pitcher - Tue, 6 Feb 2024 04:48 UTC

On Tue, 06 Feb 2024 03:05:40 +0000, Lawrence D'Oliveiro wrote:

> On Tue, 6 Feb 2024 03:01:18 -0000 (UTC), Lew Pitcher wrote:
>
>> Given that
>>>>> v_a & v_b == v_c
>> is a valid expression that binary ANDs v_a with the truth value of the
>> expression (v_b == v_c), your proposed change in operator precedence
>> would greatly affect the correctness of the expression.
>
> That’s why I asked for “real-world” examples.

While I have no "real world" examples to give you, I have no doubt
that, somewhere in the hundreds of millions of lines of C code currently
in use, there are examples of exactly this sort of code.

> Why would anyone want to
> write such an expression with the bitwise operators, instead of using the
> boolean ones?

Because they can?
Because it suits their needs?
Because they don't know better?

It doesn't matter. The C standard has, up until now, permitted such code,
and so, somewhere, someone has written it. And, now, despite your preferences,
it must be maintained.

--
Lew Pitcher
"In Skills We Trust"

Re: Operator Precedence

<86bk8u6owk.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Operator Precedence
Date: Mon, 05 Feb 2024 23:19:07 -0800
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <86bk8u6owk.fsf@linuxsc.com>
References: <ups1ok$h6mt$6@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="d2da8a4cc697e8eb8be078da8547a33d";
logging-data="825199"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+BSagvo+LaYG8hpTEa/DMQUzTCPGmPinY="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:K8EOr4e2RCeSeX+9ok9bxDTjgsM=
sha1:gecxJy4UXVxS8UBtQ7cfwhaHLJ4=
 by: Tim Rentsch - Tue, 6 Feb 2024 07:19 UTC

Lawrence D'Oliveiro <ldo@nz.invalid> writes:

> Operator precedence in C, particularly in regard to the bitwise operators,
> can be a bit awkward. Consider an expression like
>
> (val & check_bits) == set_bits
>
> which uses ?check_bits? to mask out the bits to check from ?val?, and then
> compares the result to ?set_bits?. A more natural precedence order would
> allow this to be written without the parentheses:
>
> val & check_bits == set_bits
>
> I discovered a few years ago (quite by accident) that Python does make a
> small change to the operator precedences to allow exactly this sort of
> thing.
>
> My question is, if this corresponding operator precedence change were to
> be made in C, is there any actual real-world code that would break?

Surely the answer to that question is an emphatic yes, but in any
case it's the wrong question.

An obvious first question is, if such a change were made to C
(via changes to the ISO C standard), would it result an any
significant gain? The answer to that question is No. Some
things would be easier, some things would be harder, the overall
effect on programming effort might be a net positive, but it is
as best a second-order effect: possibly a gain, but not a
significant gain.

An obvious next question is, if such a change were made to C, how
much collateral damage would result? The answer to that question
is hard to know exactly, but without doubt it is at least huge.
Consider what happened with C99. For the most part C99 was upward
compatible with C90, with two exceptions: removal of implicit
function declarations, and removal of implicit int. Furthermore
those changes would cause diagnostics if run on C90 code that
didn't fit the C99 rules. Despite that it took a very long time,
probably at least a decade, before C99 was fully embraced by the
C community. The effect of a change in precedence relationships
surely would be much, much longer. An important principle in the
evolution of C is that working code keeps working. There are some
exceptions to that principle, but they are rare and modest in
scale. The proposed precedence change would not be an evolution
of the language but a bifurcation of the language. In this case
the "cure" is worse than the disease.

Re: Operator Precedence

<upsvtf$r1jd$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Operator Precedence
Date: Tue, 6 Feb 2024 10:59:10 +0100
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <upsvtf$r1jd$1@dont-email.me>
References: <ups1ok$h6mt$6@dont-email.me> <ups2hi$hfak$1@dont-email.me>
<ups5cs$hs4o$1@dont-email.me> <874jemjp7v.fsf@nosuchdomain.example.com>
<ups716$i2ic$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 6 Feb 2024 09:59:11 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="f29298bbadbcc23825f08716f2f2dee4";
logging-data="886381"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18IaKrAUb+lG2gE4YGxRbUyU4bowPt+f6A="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:1nVNSpgpF2SNQ8jb0bVbT8YaQAA=
Content-Language: en-GB
In-Reply-To: <ups716$i2ic$1@dont-email.me>
 by: David Brown - Tue, 6 Feb 2024 09:59 UTC

On 06/02/2024 03:54, Lawrence D'Oliveiro wrote:
> On Mon, 05 Feb 2024 18:33:56 -0800, Keith Thompson wrote:
>
>> But not everyone does write it with the parentheses.
>
> Let us be clear about what we are talking about. You are suggesting that
> people write an expression like
>
> a «bitop» b «cmp» c
>
> with the expectation that it means
>
> a «bitop» (b «cmp» c)
>
> because currently in C, anybody who wants it to mean
>
> (a «bitop» b) «cmp» c
>
> has to write it that way, with explicit parentheses, anyway.
>
> The question is, who would write something like (with or without
> parentheses)
>
> a «bitop» (b «cmp» c)
>
> and why? Because a comparison in C only returns either 0 or 1, while bit
> operators are most useful dealing with multibit masks.

It's common to use && than & :

x == 1 && y == 2

People might use & rather than && because they want to avoid
short-circuit evaluation, or because they think (usually wrongly, but
sometimes people have to use weaker compilers) that it gives more
efficient code. They may also write things like :

if (x == true & y == true) ...

I'm struggling to find an example where this kind of thing would be
objectively good code, but people do write odd code. So yes, I think a
change in the precedence /would/ cause breakage, but not a lot, and
mostly in code that was a bit odd to start with. However, that's enough
to put it out of the question for a change to C.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor