Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

19 May, 2024: Line wrapping has been changed to be more consistent with Usenet standards.
 If you find that it is broken please let me know here rocksolid.nodes.help


devel / comp.lang.c / Re: How About Disallowing Assignments In Expressions?

SubjectAuthor
* How About Disallowing Assignments In Expressions?Lawrence D'Oliveiro
+* Re: How About Disallowing Assignments In Expressions?Malcolm McLean
|`* Re: How About Disallowing Assignments In Expressions?Lawrence D'Oliveiro
| `- Re: How About Disallowing Assignments In Expressions?Tim Rentsch
+- Re: How About Disallowing Assignments In Expressions?Kaz Kylheku
+* Re: How About Disallowing Assignments In Expressions?David Brown
|+* Re: How About Disallowing Assignments In Expressions?Ben Bacarisse
||+* Re: How About Disallowing Assignments In Expressions?Richard Harnden
|||`* Re: How About Disallowing Assignments In Expressions?Ben Bacarisse
||| `* Re: How About Disallowing Assignments In Expressions?Richard Harnden
|||  `* Re: How About Disallowing Assignments In Expressions?Ben Bacarisse
|||   `* Re: How About Disallowing Assignments In Expressions?Malcolm McLean
|||    `* Re: How About Disallowing Assignments In Expressions?Ben Bacarisse
|||     `- Re: How About Disallowing Assignments In Expressions?Malcolm McLean
||`* Re: How About Disallowing Assignments In Expressions?David Brown
|| +* Re: How About Disallowing Assignments In Expressions?Ben Bacarisse
|| |`- Re: How About Disallowing Assignments In Expressions?David Brown
|| `- Re: How About Disallowing Assignments In Expressions?Janis Papanagnou
|+- Re: How About Disallowing Assignments In Expressions?Kaz Kylheku
|`* Re: How About Disallowing Assignments In Expressions?Keith Thompson
| +* Re: How About Disallowing Assignments In Expressions?Malcolm McLean
| |+- Re: How About Disallowing Assignments In Expressions?Keith Thompson
| |`* Re: How About Disallowing Assignments In Expressions?bart
| | +* Re: How About Disallowing Assignments In Expressions?fir
| | |`- Re: How About Disallowing Assignments In Expressions?fir
| | `* Re: How About Disallowing Assignments In Expressions?fir
| |  `* Re: How About Disallowing Assignments In Expressions?fir
| |   +- Re: How About Disallowing Assignments In Expressions?fir
| |   `- Re: How About Disallowing Assignments In Expressions?fir
| +* Re: How About Disallowing Assignments In Expressions?Kaz Kylheku
| |+- Re: How About Disallowing Assignments In Expressions?Keith Thompson
| |`* Re: How About Disallowing Assignments In Expressions?bart
| | +- Re: How About Disallowing Assignments In Expressions?Keith Thompson
| | `- Re: How About Disallowing Assignments In Expressions?Kaz Kylheku
| +- Re: How About Disallowing Assignments In Expressions?David Brown
| +* Re: How About Disallowing Assignments In Expressions?Keith Thompson
| |+- Re: How About Disallowing Assignments In Expressions?fir
| |`* Re: How About Disallowing Assignments In Expressions?Kaz Kylheku
| | `* Re: How About Disallowing Assignments In Expressions?dave thompson 2
| |  +* Re: How About Disallowing Assignments In Expressions?Janis Papanagnou
| |  |`- Re: How About Disallowing Assignments In Expressions?bart
| |  `- Re: How About Disallowing Assignments In Expressions?Lawrence D'Oliveiro
| +* Re: How About Disallowing Assignments In Expressions?Lawrence D'Oliveiro
| |+* Re: How About Disallowing Assignments In Expressions?Kaz Kylheku
| ||`* Re: How About Disallowing Assignments In Expressions?David Brown
| || `- Re: How About Disallowing Assignments In Expressions?Lawrence D'Oliveiro
| |+* Re: How About Disallowing Assignments In Expressions?Keith Thompson
| ||`* Re: How About Disallowing Assignments In Expressions?Keith Thompson
| || `* Re: How About Disallowing Assignments In Expressions?David Brown
| ||  +* Re: How About Disallowing Assignments In Expressions?Lawrence D'Oliveiro
| ||  |`- Re: How About Disallowing Assignments In Expressions?David Brown
| ||  `- Re: How About Disallowing Assignments In Expressions?Janis Papanagnou
| |`* Re: How About Disallowing Assignments In Expressions?Ben Bacarisse
| | +* Re: How About Disallowing Assignments In Expressions?David Brown
| | |+* Re: How About Disallowing Assignments In Expressions?Ben Bacarisse
| | ||+- Re: How About Disallowing Assignments In Expressions?Ben Bacarisse
| | ||+* Re: How About Disallowing Assignments In Expressions?bart
| | |||`- Re: How About Disallowing Assignments In Expressions?David Brown
| | ||+- Re: How About Disallowing Assignments In Expressions?Lawrence D'Oliveiro
| | ||`- Re: How About Disallowing Assignments In Expressions?David Brown
| | |`* Re: How About Disallowing Assignments In Expressions?Lawrence D'Oliveiro
| | | `* Re: How About Disallowing Assignments In Expressions?Ben Bacarisse
| | |  +* Re: How About Disallowing Assignments In Expressions?Lawrence D'Oliveiro
| | |  |`* Re: How About Disallowing Assignments In Expressions?Keith Thompson
| | |  | `* Re: How About Disallowing Assignments In Expressions?Lawrence D'Oliveiro
| | |  |  `* Re: How About Disallowing Assignments In Expressions?Keith Thompson
| | |  |   +* Re: How About Disallowing Assignments In Expressions?Lawrence D'Oliveiro
| | |  |   |`* Re: How About Disallowing Assignments In Expressions?Keith Thompson
| | |  |   | `* Re: How About Disallowing Assignments In Expressions?Lawrence D'Oliveiro
| | |  |   |  `* Re: How About Disallowing Assignments In Expressions?Keith Thompson
| | |  |   |   +* Re: How About Disallowing Assignments In Expressions?Keith Thompson
| | |  |   |   |`* Re: How About Disallowing Assignments In Expressions?David Brown
| | |  |   |   | `* Re: How About Disallowing Assignments In Expressions?bart
| | |  |   |   |  `* Re: How About Disallowing Assignments In Expressions?David Brown
| | |  |   |   |   +* Re: How About Disallowing Assignments In Expressions?bart
| | |  |   |   |   |`* Re: How About Disallowing Assignments In Expressions?David Brown
| | |  |   |   |   | `- Re: How About Disallowing Assignments In Expressions?Keith Thompson
| | |  |   |   |   `* Re: How About Disallowing Assignments In Expressions?Keith Thompson
| | |  |   |   |    `- Re: How About Disallowing Assignments In Expressions?David Brown
| | |  |   |   `* Re: How About Disallowing Assignments In Expressions?Lawrence D'Oliveiro
| | |  |   |    +- Re: How About Disallowing Assignments In Expressions?Keith Thompson
| | |  |   |    `* Re: How About Disallowing Assignments In Expressions?David Brown
| | |  |   |     `* Re: How About Disallowing Assignments In Expressions?Lawrence D'Oliveiro
| | |  |   |      +* Re: How About Disallowing Assignments In Expressions?Keith Thompson
| | |  |   |      |`* Re: How About Disallowing Assignments In Expressions?Lawrence D'Oliveiro
| | |  |   |      | +- Re: How About Disallowing Assignments In Expressions?Ben Bacarisse
| | |  |   |      | `- Re: How About Disallowing Assignments In Expressions?Keith Thompson
| | |  |   |      `- Re: How About Disallowing Assignments In Expressions?David Brown
| | |  |   `* Re: How About Disallowing Assignments In Expressions?Malcolm McLean
| | |  |    `* Re: How About Disallowing Assignments In Expressions?David Brown
| | |  |     +* Re: How About Disallowing Assignments In Expressions?Malcolm McLean
| | |  |     |`* Re: How About Disallowing Assignments In Expressions?David Brown
| | |  |     | `* Re: How About Disallowing Assignments In Expressions?Malcolm McLean
| | |  |     |  `* Re: How About Disallowing Assignments In Expressions?David Brown
| | |  |     |   `* Re: How About Disallowing Assignments In Expressions?Malcolm McLean
| | |  |     |    `* Re: How About Disallowing Assignments In Expressions?David Brown
| | |  |     |     +* Re: How About Disallowing Assignments In Expressions?Malcolm McLean
| | |  |     |     |`- Re: How About Disallowing Assignments In Expressions?David Brown
| | |  |     |     `* Re: How About Disallowing Assignments In Expressions?bart
| | |  |     |      +- Re: How About Disallowing Assignments In Expressions?Ben Bacarisse
| | |  |     |      `* Re: How About Disallowing Assignments In Expressions?David Brown
| | |  |     +* Re: How About Disallowing Assignments In Expressions?Lawrence D'Oliveiro
| | |  |     `* Re: How About Disallowing Assignments In Expressions?Janis Papanagnou
| | |  `* Re: How About Disallowing Assignments In Expressions?David Brown
| | +* Re: How About Disallowing Assignments In Expressions?Lawrence D'Oliveiro
| | `- Re: How About Disallowing Assignments In Expressions?Keith Thompson
| +- Re: How About Disallowing Assignments In Expressions?Janis Papanagnou
| `* Re: How About Disallowing Assignments In Expressions?Michael S
+* Re: How About Disallowing Assignments In Expressions?bart
+* Re: How About Disallowing Assignments In Expressions?Blue-Maned_Hawk
+- Re: How About Disallowing Assignments In Expressions?Richard Kettlewell
`* Re: How About Disallowing Assignments In Expressions?Thiago Adams

Pages:123456789101112131415161718192021
Re: How About Disallowing Assignments In Expressions?

<uq633t$25349$1@i2pn2.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!.POSTED!not-for-mail
From: fir@grunge.pl (fir)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Fri, 09 Feb 2024 21:48:57 +0100
Organization: i2pn2 (i2pn.org)
Message-ID: <uq633t$25349$1@i2pn2.org>
References: <uq3s76$28dsr$1@dont-email.me> <uq4nmb$2hive$6@dont-email.me> <87r0hlef8q.fsf@nosuchdomain.example.com> <uq5n06$2nkds$1@dont-email.me> <uq5pbq$2nvst$1@dont-email.me> <uq5rtn$24oum$1@i2pn2.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 9 Feb 2024 20:49:01 -0000 (UTC)
Injection-Info: i2pn2.org;
logging-data="2264201"; mail-complaints-to="usenet@i2pn2.org";
posting-account="+ydHcGjgSeBt3Wz3WTfKefUptpAWaXduqfw5xdfsuS0";
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0 SeaMonkey/2.24
In-Reply-To: <uq5rtn$24oum$1@i2pn2.org>
X-Spam-Checker-Version: SpamAssassin 4.0.0
 by: fir - Fri, 9 Feb 2024 20:48 UTC

fir wrote:
> bart wrote:
>> On 09/02/2024 17:22, Malcolm McLean wrote:
>>> On 09/02/2024 17:09, Keith Thompson wrote:
>>>>
>>>> (It's possible I'm overgeneralizing. For example, a programmer who
>>>> commonly switches between C and other languages might still mix up "="
>>>> and "==" occasionally.)
>>>>
>>>
>>> I had do to my PhD in Fortran, for my sins. It's := for assignment and
>>> = for comparison, and when I switched back to C, I was always writing
>>> "=" for "==".
>>
>> Fortran must have changed considerably since I last used it.
>>
>> It was "=" to assign, and ".EQ." for equality.
>>
>> I assume you mean another language. My normal one does use := and = like
>> that, and switching to/from C gives problems: you write = in C instead
>> of ==, and in mine I'd write = instead of :=. However:
>>
>> a = b
>>
>> was a no-op in my language (or rather, it compared then discarded the
>> result), leading to puzzling bugs. Now I usually detect such statements.
>
> as some maybe know im from time to time write my compiler on c based
> langage and also i hardly think how to simplify and expand syntax and
> construction
>
> as to this problem how ewentually replace = and == at present time i
> just found this problem unresolvable :c
>
>
> what i think = coud eventually stay though it also could have
> alternative.. == is in turn clearly wrong but one would need unicode
> sign for this i guess.. there is need for some sign like = with a small
> "?" above it
>
> ≟ possibly
>
> a≟b
>
in fact i could conclude:

a=b assigment should be something that resembles "=" but in the
direction of <- or something like that
a==b comparsion should be something that resembles "=" but in the
direction of something like comparsion sign

bioth obviously should be one sign..in asci there is no way to resolve
that i guess

i guess even = could be for comparsion but yopu would need another =
more in direction like <- (but not quite) for assigments

in asci that cont be done properly (i think)
in asci you only can have some aproximation of this, and i probably
would hold a=b for assigment and use a?=b for comparison (but only as
approximation and use unicode for full 'version')

Re: How About Disallowing Assignments In Expressions?

<8734u1e424.fsf@nosuchdomain.example.com>

  copy mid

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

  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: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Fri, 09 Feb 2024 13:11:15 -0800
Organization: None to speak of
Lines: 23
Message-ID: <8734u1e424.fsf@nosuchdomain.example.com>
References: <uq3s76$28dsr$1@dont-email.me> <uq4nmb$2hive$6@dont-email.me>
<87r0hlef8q.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="639f38d912c33920e0e5a36e0f09675f";
logging-data="2951029"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19vdYB8lF0kysnnFNH8r9Xk"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:pMleOTwuct4aX+uxQH/FDTVmvFk=
sha1:4zjbtojZi1EmzYRfc5n1xkUCQZY=
 by: Keith Thompson - Fri, 9 Feb 2024 21:11 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
[...]
> If C had used ":=" for assignment and "=" for comparison (and "=="
> probably not used for anything), the problem would never have come up,
> because ":=" doesn't look like a comparison even to a newbie. But it's
> far too late to fix that in any language called "C".

If I were designing a new language, I'd consider using ":=" for
assignment, "==" for equality, and not using "=" for anything.

In (nearly?) all languages I'm aware of, ":=" either doesn't exist or
means assignment, and "==" either doesn't exist or means equality. I'd
avoid "=" because it's ambiguous across languages (and that's almost
entirely C's fault, inherited from B).

Historically, C's predecessor B used "=" for assignment and "==" for
equality, while B's predecessor BCPL used ":=" for assignment and "="
for equality.

--
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: How About Disallowing Assignments In Expressions?

<uq65j6$2psod$11@dont-email.me>

  copy mid

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

  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: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Fri, 9 Feb 2024 21:31:18 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <uq65j6$2psod$11@dont-email.me>
References: <uq3s76$28dsr$1@dont-email.me>
<pan$68183$c20f769a$773bf670$77626466@invalid.invalid>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 9 Feb 2024 21:31:18 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6b81b1b5b0886ece37827f7a23070dda";
logging-data="2945805"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19g2NMqzzDgh+iGgmlPpCKO"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:Jlbnpb4taVjyMZlbSBKyu9emcPQ=
 by: Lawrence D'Oliv - Fri, 9 Feb 2024 21:31 UTC

On Fri, 9 Feb 2024 19:47:45 -0000 (UTC), Blue-Maned_Hawk wrote:

> There are too many situations where assignment being an expression is a
> useful facet of the language; i am not willing to sacrifice that for an
> ill-defined ideal of “safety”.

If you consider it “ill-defined”, consider the number of people who have
developed the habit of writing

if (NULL == p) ...

instead of the more natural

if (p == NULL) ...

Re: How About Disallowing Assignments In Expressions?

<uq67u9$259v5$1@i2pn2.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!.POSTED!not-for-mail
From: fir@grunge.pl (fir)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Fri, 09 Feb 2024 23:11:16 +0100
Organization: i2pn2 (i2pn.org)
Message-ID: <uq67u9$259v5$1@i2pn2.org>
References: <uq3s76$28dsr$1@dont-email.me> <uq4nmb$2hive$6@dont-email.me> <87r0hlef8q.fsf@nosuchdomain.example.com> <8734u1e424.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 9 Feb 2024 22:11:22 -0000 (UTC)
Injection-Info: i2pn2.org;
logging-data="2271205"; mail-complaints-to="usenet@i2pn2.org";
posting-account="+ydHcGjgSeBt3Wz3WTfKefUptpAWaXduqfw5xdfsuS0";
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0 SeaMonkey/2.24
X-Spam-Checker-Version: SpamAssassin 4.0.0
In-Reply-To: <8734u1e424.fsf@nosuchdomain.example.com>
 by: fir - Fri, 9 Feb 2024 22:11 UTC

Keith Thompson wrote:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
> [...]
>> If C had used ":=" for assignment and "=" for comparison (and "=="
>> probably not used for anything), the problem would never have come up,
>> because ":=" doesn't look like a comparison even to a newbie. But it's
>> far too late to fix that in any language called "C".
>
> If I were designing a new language, I'd consider using ":=" for
> assignment, "==" for equality, and not using "=" for anything.
>
> In (nearly?) all languages I'm aware of, ":=" either doesn't exist or
> means assignment, and "==" either doesn't exist or means equality. I'd
> avoid "=" because it's ambiguous across languages (and that's almost
> entirely C's fault, inherited from B).
>
> Historically, C's predecessor B used "=" for assignment and "==" for
> equality, while B's predecessor BCPL used ":=" for assignment and "="
> for equality.
>

it io not in the spirit of c (and c design intentions) SO
people like you or the guy who want to consider to remove
assigments in expressions dont understand c
(i understand it at least better, question is if fully)

Re: How About Disallowing Assignments In Expressions?

<20240209141128.782@kylheku.com>

  copy mid

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

  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-6894@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Fri, 9 Feb 2024 22:14:19 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <20240209141128.782@kylheku.com>
References: <uq3s76$28dsr$1@dont-email.me> <uq4nmb$2hive$6@dont-email.me>
<87r0hlef8q.fsf@nosuchdomain.example.com>
<8734u1e424.fsf@nosuchdomain.example.com>
Injection-Date: Fri, 9 Feb 2024 22:14:19 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="f0d9c4d56e1bf3d087a60d362bc7520c";
logging-data="2972025"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18I3xEQOIuouqtJiY/u6YhSPOdE4gk7+tM="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:GzVgwAoBJGO0uu8VtyQraKO6lps=
 by: Kaz Kylheku - Fri, 9 Feb 2024 22:14 UTC

On 2024-02-09, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
> [...]
>> If C had used ":=" for assignment and "=" for comparison (and "=="
>> probably not used for anything), the problem would never have come up,
>> because ":=" doesn't look like a comparison even to a newbie. But it's
>> far too late to fix that in any language called "C".
>
> If I were designing a new language, I'd consider using ":=" for
> assignment, "==" for equality, and not using "=" for anything.
>
> In (nearly?) all languages I'm aware of, ":=" either doesn't exist or
> means assignment, and "==" either doesn't exist or means equality. I'd
> avoid "=" because it's ambiguous across languages (and that's almost
> entirely C's fault, inherited from B).

Some of the credit must go to classic BASIC!

I seem to remember than in classic, line-numbered BASICs on 8 bit
micros, the = token was used both for assignment and comparison!

300 I = I + 1
310 IF I = 10 GOTO 340

If you have a dedicated assignment statement, you can pull this kind
of stunt. Just like C can distinguish initialization from assignment.

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

Re: How About Disallowing Assignments In Expressions?

<87a5o9p8g0.fsf@bsb.me.uk>

  copy mid

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

  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: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Fri, 09 Feb 2024 22:41:03 +0000
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <87a5o9p8g0.fsf@bsb.me.uk>
References: <uq3s76$28dsr$1@dont-email.me> <uq4nmb$2hive$6@dont-email.me>
<878r3uq6we.fsf@bsb.me.uk> <uq4v6u$2j4pb$1@dont-email.me>
<87le7tpyig.fsf@bsb.me.uk> <uq5blg$2ljq3$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="c235c3c701c62e624897d4b41eb7a3c2";
logging-data="2980145"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX193TD9uUpiIsxuleO5D4Hb3qdfdfxeRtlI="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:SU2aVz7M6EGY9A1ejxKCWG8FrFM=
sha1:Ff3IuWfkmakeaEtovvh/aNCD/YE=
X-BSB-Auth: 1.d4d4c9d52de07516f8b6.20240209224103GMT.87a5o9p8g0.fsf@bsb.me.uk
 by: Ben Bacarisse - Fri, 9 Feb 2024 22:41 UTC

Richard Harnden <richard.nospam@gmail.invalid> writes:

> On 09/02/2024 13:17, Ben Bacarisse wrote:
>> Richard Harnden <richard.nospam@gmail.invalid> writes:
>>
>>> On 09/02/2024 10:16, Ben Bacarisse wrote:
>>>> David Brown <david.brown@hesbynett.no> writes:
>>>>
>>>>> On 09/02/2024 01:39, Lawrence D'Oliveiro wrote:
>>>>>> If you want to make C a safer language, one obvious thing is to disallow
>>>>>> using “=” in the middle of an expression. Instead of returning the value
>>>>>> of the expression, have it return void. Or just disallow it syntactically
>>>>>> altogether.
>>>>>
>>>>> I think that C would have been a safer language if assignment had been a
>>>>> statement, not an expression
>>>> Surely someone has studied this, no? There must be some paper
>>>> describing bugs "in the wild"* and categorising them by what language
>>>> features would have made them either impossible or less likely. I don't
>>>> know of any (it was not even remotely my field) but there is such a
>>>> large pool of data out there I can't imagine that it's not been done.
>>>> * I mean to exclude bugs that get found early. For example, I've never
>>>> seen a = vs. == bug that survived even the most crude tests (and most,
>>>> like many other typo bugs, don't survive compilation without being
>>>> picked up).
>>>
>>> This is what ChatGPT says ...
>> Seriously? You do know how large language models work, yes?
>>
>
> Sure: It has read the entire internet - especially the the bit about how
> Rust is better than C, apparently - and regurgitates the same.
>
> Considering my five seconds of effort; I didn't think it was /that/ bad of
> a list.

Yes, it's a good summary of what passes for "common knowledge". But I
was talking about something else altogether -- actual bugs found in real
code, maybe taken from an analysis of security advisories. How many can
(to take one example) be attributed, in whole or in part, for using
assignment in a larger expression?

--
Ben.

Re: How About Disallowing Assignments In Expressions?

<874jehp8cj.fsf@bsb.me.uk>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Fri, 09 Feb 2024 22:43:08 +0000
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <874jehp8cj.fsf@bsb.me.uk>
References: <uq3s76$28dsr$1@dont-email.me> <uq4nmb$2hive$6@dont-email.me>
<878r3uq6we.fsf@bsb.me.uk> <uq5a6r$2lc87$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="c235c3c701c62e624897d4b41eb7a3c2";
logging-data="2980145"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19EZ0hWsJhQBKpXK2SNXl9PMgLh6681KvA="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:sXK5t903aOAHnU69QsY60GQi0zQ=
sha1:cpncKJBQQ8jH6FmgH4eKT3oG+fE=
X-BSB-Auth: 1.d2976510dd2464b47a13.20240209224308GMT.874jehp8cj.fsf@bsb.me.uk
 by: Ben Bacarisse - Fri, 9 Feb 2024 22:43 UTC

David Brown <david.brown@hesbynett.no> writes:

> On 09/02/2024 11:16, Ben Bacarisse wrote:
>> David Brown <david.brown@hesbynett.no> writes:
>>
>>> On 09/02/2024 01:39, Lawrence D'Oliveiro wrote:
>>>> If you want to make C a safer language, one obvious thing is to disallow
>>>> using “=” in the middle of an expression. Instead of returning the value
>>>> of the expression, have it return void. Or just disallow it syntactically
>>>> altogether.
>>>
>>> I think that C would have been a safer language if assignment had been a
>>> statement, not an expression
>> Surely someone has studied this, no? There must be some paper
>> describing bugs "in the wild"* and categorising them by what language
>> features would have made them either impossible or less likely. I don't
>> know of any (it was not even remotely my field) but there is such a
>> large pool of data out there I can't imagine that it's not been done.
>
> I think it is very difficult to get good statistics on this kind of thing.
> You can't really do a controlled study comparing one group programming in
> "C where assignment is an expression" with a group programming in "C where
> assignment is a statement". And you certainly can't do a double-blind
> placebo controlled test!

True. But there are literally thousands of significant bugs logged
every day in key systems components. A retrospective analysis of these
would, I think, be very interesting.

--
Ben.

Re: How About Disallowing Assignments In Expressions?

<uq6dus$2rkfe$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: malcolm.arthur.mclean@gmail.com (Malcolm McLean)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Fri, 9 Feb 2024 23:54:02 +0000
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <uq6dus$2rkfe$1@dont-email.me>
References: <uq3s76$28dsr$1@dont-email.me> <uq4nmb$2hive$6@dont-email.me>
<878r3uq6we.fsf@bsb.me.uk> <uq4v6u$2j4pb$1@dont-email.me>
<87le7tpyig.fsf@bsb.me.uk> <uq5blg$2ljq3$1@dont-email.me>
<87a5o9p8g0.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 9 Feb 2024 23:54:04 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="f1ffd46acf87320bfb11b15ae24bdde1";
logging-data="3002862"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18+8mvSEKTZm/zw1xC4YbhX/uoiIDiaye0="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:aZYtrX+sAUmncC8B7HIE4GkoD0Y=
Content-Language: en-GB
In-Reply-To: <87a5o9p8g0.fsf@bsb.me.uk>
 by: Malcolm McLean - Fri, 9 Feb 2024 23:54 UTC

On 09/02/2024 22:41, Ben Bacarisse wrote:
> Richard Harnden <richard.nospam@gmail.invalid> writes:
>
>> On 09/02/2024 13:17, Ben Bacarisse wrote:
>>> Richard Harnden <richard.nospam@gmail.invalid> writes:
>>>
>>>> On 09/02/2024 10:16, Ben Bacarisse wrote:
>>>>> David Brown <david.brown@hesbynett.no> writes:
>>>>>
>>>>>> On 09/02/2024 01:39, Lawrence D'Oliveiro wrote:
>>>>>>> If you want to make C a safer language, one obvious thing is to disallow
>>>>>>> using “=” in the middle of an expression. Instead of returning the value
>>>>>>> of the expression, have it return void. Or just disallow it syntactically
>>>>>>> altogether.
>>>>>>
>>>>>> I think that C would have been a safer language if assignment had been a
>>>>>> statement, not an expression
>>>>> Surely someone has studied this, no? There must be some paper
>>>>> describing bugs "in the wild"* and categorising them by what language
>>>>> features would have made them either impossible or less likely. I don't
>>>>> know of any (it was not even remotely my field) but there is such a
>>>>> large pool of data out there I can't imagine that it's not been done.
>>>>> * I mean to exclude bugs that get found early. For example, I've never
>>>>> seen a = vs. == bug that survived even the most crude tests (and most,
>>>>> like many other typo bugs, don't survive compilation without being
>>>>> picked up).
>>>>
>>>> This is what ChatGPT says ...
>>> Seriously? You do know how large language models work, yes?
>>>
>>
>> Sure: It has read the entire internet - especially the the bit about how
>> Rust is better than C, apparently - and regurgitates the same.
>>
>> Considering my five seconds of effort; I didn't think it was /that/ bad of
>> a list.
>
> Yes, it's a good summary of what passes for "common knowledge". But I
> was talking about something else altogether -- actual bugs found in real
> code, maybe taken from an analysis of security advisories. How many can
> (to take one example) be attributed, in whole or in part, for using
> assignment in a larger expression?
>
I did have an example recently in my own code recently (shipped,
commercial, tested, supposedly bug free code). There was an assignment
in a if expression which somehow slipped through. But it's only one
example.
--
Check out Basic Algorithms and my other books:
https://www.lulu.com/spotlight/bgy1mm

Re: How About Disallowing Assignments In Expressions?

<uq6nha$2spqe$3@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!paganini.bofh.team!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: How About Disallowing Assignments In Expressions?
Date: Sat, 10 Feb 2024 02:37:30 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 6
Message-ID: <uq6nha$2spqe$3@dont-email.me>
References: <uq3s76$28dsr$1@dont-email.me> <uq4nmb$2hive$6@dont-email.me>
<87r0hlef8q.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 10 Feb 2024 02:37:30 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cb0aecca639ac885e888a888c6c2d7ce";
logging-data="3041102"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19+V1SC5NKH2/EGia67Bxg/"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:ialQUnMzuIPknAORCEc7Z+TVqOM=
 by: Lawrence D'Oliv - Sat, 10 Feb 2024 02:37 UTC

On Fri, 09 Feb 2024 09:09:41 -0800, Keith Thompson wrote:

> But it's far too late to fix that in any language called "C".

I had a look at the MISRA specs, and they say “assignment operators shall
not be used in expressions that yield a boolean value”.

Re: How About Disallowing Assignments In Expressions?

<20240209190146.125@kylheku.com>

  copy mid

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

  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-6894@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Sat, 10 Feb 2024 03:06:48 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <20240209190146.125@kylheku.com>
References: <uq3s76$28dsr$1@dont-email.me> <uq4nmb$2hive$6@dont-email.me>
<87r0hlef8q.fsf@nosuchdomain.example.com> <uq6nha$2spqe$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 10 Feb 2024 03:06:48 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3de03a7474c831a6f9d55487e9415a62";
logging-data="3176849"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Y1ev2r4KrM7WRZNf+vhKNf/GYoiELSJ8="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:1U2siq3QSOIGnLfhSl0pYndx3OI=
 by: Kaz Kylheku - Sat, 10 Feb 2024 03:06 UTC

On 2024-02-10, Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
> On Fri, 09 Feb 2024 09:09:41 -0800, Keith Thompson wrote:
>
>> But it's far too late to fix that in any language called "C".
>
> I had a look at the MISRA specs, and they say “assignment operators shall
> not be used in expressions that yield a boolean value”.

I skimmed through MISRA some years ago and wasn't very impressed by it,
actually.

It's full the kind of coding rules that you might want to enforce
if you have to produce a bunch of C, and the only people you are given
are ones who shouldn't even remotely be doing such a thing.

We might call those coders Les MISRAbles. :)

The rules are not suitable for people who know what they are doing
(and use tools effectively) and detrimental to the code.

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

Re: How About Disallowing Assignments In Expressions?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.network!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Fri, 09 Feb 2024 20:16:37 -0800
Organization: None to speak of
Lines: 15
Message-ID: <87jzndc5sq.fsf@nosuchdomain.example.com>
References: <uq3s76$28dsr$1@dont-email.me> <uq4nmb$2hive$6@dont-email.me>
<87r0hlef8q.fsf@nosuchdomain.example.com>
<uq6nha$2spqe$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="3b6abb86f0f3816027ad8c34cf97d3ff";
logging-data="3194447"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18VctQB5u1oJp9IoAair9IJ"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:UjJhIqOw2T/Ov1RIqw8tfY7wMhY=
sha1:w1WJnfPFiR8kUj+mVwJuFVE9zBI=
 by: Keith Thompson - Sat, 10 Feb 2024 04:16 UTC

Lawrence D'Oliveiro <ldo@nz.invalid> writes:
> On Fri, 09 Feb 2024 09:09:41 -0800, Keith Thompson wrote:
>> But it's far too late to fix that in any language called "C".
>
> I had a look at the MISRA specs, and they say “assignment operators shall
> not be used in expressions that yield a boolean value”.

I presume they mean expressions used as conditions, but unless they
define what they the phrase "boolean value" somwhere, that's not what
they wrote.

--
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: How About Disallowing Assignments In Expressions?

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

  copy mid

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

  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: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Fri, 09 Feb 2024 20:17:51 -0800
Organization: None to speak of
Lines: 22
Message-ID: <87fry1c5qo.fsf@nosuchdomain.example.com>
References: <uq3s76$28dsr$1@dont-email.me> <uq4nmb$2hive$6@dont-email.me>
<87r0hlef8q.fsf@nosuchdomain.example.com>
<uq6nha$2spqe$3@dont-email.me>
<87jzndc5sq.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="3b6abb86f0f3816027ad8c34cf97d3ff";
logging-data="3194447"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+XMZQgSk9MC54zmpizJCzV"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:fqieX6LAw04sTkKPoGAelGRnCv0=
sha1:K08QQvnsHNgdKyIL5eTmp3kh8iQ=
 by: Keith Thompson - Sat, 10 Feb 2024 04:17 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>> On Fri, 09 Feb 2024 09:09:41 -0800, Keith Thompson wrote:
>>> But it's far too late to fix that in any language called "C".
>>
>> I had a look at the MISRA specs, and they say “assignment operators shall
>> not be used in expressions that yield a boolean value”.
>
> I presume they mean expressions used as conditions, but unless they
> define what they the phrase "boolean value" somwhere, that's not what
> they wrote.

Editing error.

I presume they mean expressions used as conditions, but unless they
define what they *mean by* the phrase "boolean value" somwhere, that's
not what they wrote.

--
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: How About Disallowing Assignments In Expressions?

<pan$26eef$4f4fde86$8b9cd01b$37f2c6db@invalid.invalid>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!bluemanedhawk.eternal-september.org!.POSTED!not-for-mail
From: bluemanedhawk@invalid.invalid (Blue-Maned_Hawk)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Sat, 10 Feb 2024 08:05:53 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <pan$26eef$4f4fde86$8b9cd01b$37f2c6db@invalid.invalid>
References: <uq3s76$28dsr$1@dont-email.me>
<pan$68183$c20f769a$773bf670$77626466@invalid.invalid>
<uq65j6$2psod$11@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 10 Feb 2024 08:05:53 -0000 (UTC)
Injection-Info: bluemanedhawk.eternal-september.org; posting-host="1d7baf03dfa5ea387052f99113fcc5ef";
logging-data="3251810"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18583GJqgbPszpaTfRhD4YZfGxnwO61wOs="
User-Agent: Pan/0.154 (Izium; 517acf4)
Cancel-Lock: sha1:3PwHHAxl/Qaq2HPkALIzct19jwA=
Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAIAAADYYG7QAAACh0lEQVRYw71Z21bD
MAzzevbfkr4cHjrSXJyL044+MDa6WLEl2SkvkrZ1AbAvXO+bUGSCPYnsuIVGMpm
ZLnjX718GhAKNsp8lON2F9VrhELwIgJlBepkZjA78rVK+FkmNhEJK76UsJlz8+E
rJsjrpYouhLo/SC6qPHgakFOR8wV9+8rCfO/I/oVnmUZUp42/LW2XkLj9TCFNM9
jp5g2EmHZgpYZjCOkYU7sXVogRylJqpdggoFLG1g09Flah/7kErCxzR9HgXPYsq
0glb9cxjIz2Vsk9AmAoCSxECpD713joMKjQqLAtmMqJmXjdVvlMnMQCVITotJd1
z+fh1f1NNo+vuc1KnhWUmY7t03vydTud9BbXCtN3L2PL3bK7JCNG0GHzuZxafyB
fxevCxpm1vrwZltqw6SILCcdoCE6PGQC8wZWDA9Or7Qp5s3lAZezys0nDazs9S9
R0TjwEiksRxLkNPC1NMMWPs1bj0Ei0Yuo+JVtFLuzP1NRJ16qXWN8DhhtmS4PDg
O6mqRxs4bEJrYt087mSIow/1VzW2oFlMQuiuIy/KsUagvhdw6hSjJGlIavbLF8x
j3X47bccLcUSi0dkWh1nUZNhANT1tHKUXrNxNLbd9KPb9wDDVrKwmPQMOPQ1oy6
k5I1DwzDeRJd3jVIhDAUxq3ngzJG4CCkNXZxZVMcjefoK2J0gUY2S3rxz/RuTFx
2zHd9U+obimJXMG4edsk/2j5pTU5G1MmzbRLxkfq5EiT1GGsidvMGzi+1goGb2l
GCrN+nGnV8xj3q3JLRDVPL96vUc7Z4aJ3TN1mVqWAMJMfG+Jxh6TQqP+92iZkCU
xtglds1AB6r0aiSHKcnFck+p/c/0CbacFLQcajGcAAAAASUVORK5CYII=
X-Face: Llanfair­pwllgwyng
yll
­gogeryÂÃ
? ?­chwyrnÂÂÂÂÂÂ
­drobwll­llanÃ
‚Ã
ƒƒƒ‚­tysilioÂÂÂÃ
‚­gogo­goch
 by: Blue-Maned_Hawk - Sat, 10 Feb 2024 08:05 UTC

Lawrence D'Oliveiro wrote:

> On Fri, 9 Feb 2024 19:47:45 -0000 (UTC), Blue-Maned_Hawk wrote:
>
>> There are too many situations where assignment being an expression is a
>> useful facet of the language; i am not willing to sacrifice that for an
>> ill-defined ideal of “safety”.
>
> If you consider it “ill-defined”, consider the number of people who have
> developed the habit of writing
>
> if (NULL == p) ...
>
> instead of the more natural
>
> if (p == NULL) ...

Y'know, there's some coding style guide that explicitly states _not_ to do
those kinds of “yoda comparisons”, but i've never seen any code that
actually uses them.

--
Blue-Maned_Hawk│shortens to
Hawk│/
blu.mɛin.dÊ°ak/
│he/him/his/himself/Mr.
blue-maned_hawk.srht.site
LOCAL MAN'S SPEECH ENTIRELY INCONSEQUENTIAL

Re: How About Disallowing Assignments In Expressions?

<87y1bso4iv.fsf@bsb.me.uk>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.bbs.nz!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Sat, 10 Feb 2024 13:03:20 +0000
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <87y1bso4iv.fsf@bsb.me.uk>
References: <uq3s76$28dsr$1@dont-email.me> <uq4nmb$2hive$6@dont-email.me>
<878r3uq6we.fsf@bsb.me.uk> <uq4v6u$2j4pb$1@dont-email.me>
<87le7tpyig.fsf@bsb.me.uk> <uq5blg$2ljq3$1@dont-email.me>
<87a5o9p8g0.fsf@bsb.me.uk> <uq6dus$2rkfe$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="c13342fcfa2cdc30d6c9e83b0b27a1c1";
logging-data="3346647"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18iGDzmo29dOvyR1vVnpJUvsYVy+ZnJYjg="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:pF0ouxsHSvzs9Xb70y3dmum44M8=
sha1:Jx6G4GRTj9uIFd1QLCtOvLZGrIM=
X-BSB-Auth: 1.8ffa9e7d3c3ddd7fac5f.20240210130320GMT.87y1bso4iv.fsf@bsb.me.uk
 by: Ben Bacarisse - Sat, 10 Feb 2024 13:03 UTC

Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:

> On 09/02/2024 22:41, Ben Bacarisse wrote:
....
>> Yes, it's a good summary of what passes for "common knowledge". But I
>> was talking about something else altogether -- actual bugs found in real
>> code, maybe taken from an analysis of security advisories. How many can
>> (to take one example) be attributed, in whole or in part, for using
>> assignment in a larger expression?
>>
> I did have an example recently in my own code recently (shipped,
> commercial, tested, supposedly bug free code). There was an assignment in a
> if expression which somehow slipped through. But it's only one
> example.

Can you post a link to the post? I know you've switch readers, so it
may not be obvious how to do that, but I'd appreciate it.

--
Ben.

Re: How About Disallowing Assignments In Expressions?

<87sf20o4e2.fsf@bsb.me.uk>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.chmurka.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Sat, 10 Feb 2024 13:06:13 +0000
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <87sf20o4e2.fsf@bsb.me.uk>
References: <uq3s76$28dsr$1@dont-email.me> <uq4nmb$2hive$6@dont-email.me>
<87r0hlef8q.fsf@nosuchdomain.example.com>
<uq6nha$2spqe$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="c13342fcfa2cdc30d6c9e83b0b27a1c1";
logging-data="3346647"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX194h+PDEfFpkSFPN27yll67odgQ+aLgWfQ="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:2ZA5LwvHwqIsetDXprENwc3H7LI=
sha1:PnMbSJB1JOxK7B/jIC20swRdBLI=
X-BSB-Auth: 1.1ce65390cd228ef5265f.20240210130613GMT.87sf20o4e2.fsf@bsb.me.uk
 by: Ben Bacarisse - Sat, 10 Feb 2024 13:06 UTC

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

> On Fri, 09 Feb 2024 09:09:41 -0800, Keith Thompson wrote:
>
>> But it's far too late to fix that in any language called "C".
>
> I had a look at the MISRA specs, and they say “assignment operators shall
> not be used in expressions that yield a boolean value”.

Oddly worded. They can't mean what they say.

--
Ben.

Re: How About Disallowing Assignments In Expressions?

<uq7ug4$36h0h$1@dont-email.me>

  copy mid

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

  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.brown@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Sat, 10 Feb 2024 14:42:28 +0100
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <uq7ug4$36h0h$1@dont-email.me>
References: <uq3s76$28dsr$1@dont-email.me> <uq4nmb$2hive$6@dont-email.me>
<878r3uq6we.fsf@bsb.me.uk> <uq5a6r$2lc87$1@dont-email.me>
<874jehp8cj.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 10 Feb 2024 13:42:28 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="94c27d23ea8de2abb521791d5d2342a2";
logging-data="3359761"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/EbAfwaN5G6Az6h8Ko75EIZhZveMQtDwY="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Ov9z0OErNqR6n1hFgW0aO9hpgH8=
Content-Language: en-GB
In-Reply-To: <874jehp8cj.fsf@bsb.me.uk>
 by: David Brown - Sat, 10 Feb 2024 13:42 UTC

On 09/02/2024 23:43, Ben Bacarisse wrote:
> David Brown <david.brown@hesbynett.no> writes:
>
>> On 09/02/2024 11:16, Ben Bacarisse wrote:
>>> David Brown <david.brown@hesbynett.no> writes:
>>>
>>>> On 09/02/2024 01:39, Lawrence D'Oliveiro wrote:
>>>>> If you want to make C a safer language, one obvious thing is to disallow
>>>>> using “=” in the middle of an expression. Instead of returning the value
>>>>> of the expression, have it return void. Or just disallow it syntactically
>>>>> altogether.
>>>>
>>>> I think that C would have been a safer language if assignment had been a
>>>> statement, not an expression
>>> Surely someone has studied this, no? There must be some paper
>>> describing bugs "in the wild"* and categorising them by what language
>>> features would have made them either impossible or less likely. I don't
>>> know of any (it was not even remotely my field) but there is such a
>>> large pool of data out there I can't imagine that it's not been done.
>>
>> I think it is very difficult to get good statistics on this kind of thing.
>> You can't really do a controlled study comparing one group programming in
>> "C where assignment is an expression" with a group programming in "C where
>> assignment is a statement". And you certainly can't do a double-blind
>> placebo controlled test!
>
> True. But there are literally thousands of significant bugs logged
> every day in key systems components. A retrospective analysis of these
> would, I think, be very interesting.
>

That would be interesting, yes. It sounds like a good task for a
postgraduate student thesis.

Re: How About Disallowing Assignments In Expressions?

<uq7vlm$36orr$1@dont-email.me>

  copy mid

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

  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.brown@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Sat, 10 Feb 2024 15:02:30 +0100
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <uq7vlm$36orr$1@dont-email.me>
References: <uq3s76$28dsr$1@dont-email.me> <uq4nmb$2hive$6@dont-email.me>
<87r0hlef8q.fsf@nosuchdomain.example.com> <uq6nha$2spqe$3@dont-email.me>
<20240209190146.125@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 10 Feb 2024 14:02:30 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="94c27d23ea8de2abb521791d5d2342a2";
logging-data="3367803"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18HR+8qYfL5kPIN6DCsr1pZCPEWnLyE4w4="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:BbhVM+6PQab7bC4WpnpfcsPyYbI=
Content-Language: en-GB
In-Reply-To: <20240209190146.125@kylheku.com>
 by: David Brown - Sat, 10 Feb 2024 14:02 UTC

On 10/02/2024 04:06, Kaz Kylheku wrote:
> On 2024-02-10, Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
>> On Fri, 09 Feb 2024 09:09:41 -0800, Keith Thompson wrote:
>>
>>> But it's far too late to fix that in any language called "C".
>>
>> I had a look at the MISRA specs, and they say “assignment operators shall
>> not be used in expressions that yield a boolean value”.
>
> I skimmed through MISRA some years ago and wasn't very impressed by it,
> actually.
>
> It's full the kind of coding rules that you might want to enforce
> if you have to produce a bunch of C, and the only people you are given
> are ones who shouldn't even remotely be doing such a thing.
>
> We might call those coders Les MISRAbles. :)
>
> The rules are not suitable for people who know what they are doing
> (and use tools effectively) and detrimental to the code.
>

The MISRA rules are a mixed bag. Some of them are definitely things
that should be considered obvious - such as "don't rely on the results
of undefined behaviour". And some are also more appropriate for people
using poorer tools (or who don't know how to use their tools well).
Some are directly unhelpful - it talks about an "effective type" system
that is, as I recall, subtly wrong.

It is worth remembering the target audience, especially for older
versions of MISRA (their rules have been updated several times). It
used to be the norm that compilers for microcontrollers were a bit odd -
they could be very poor at optimising (leading to people doing dangerous
tricks, or at least unclear code, to get faster results), and poor at
warnings. They often had lots of extensions, and non-conforming
features. (I've seen an 8-bit sort-of-C compiler that intentionally
does not promote 8-bit types to "int" as required - and that was a big
name, big price toolchain.) These tools also change slowly - many did
not have decent C99 support until perhaps fifteen years ago, so you
couldn't use the newer and better C version. And the tools can have
more bugs than more popular toolchains with wider audiences.

A fair proportion of people programming for small embedded systems are
primarily electronics engineers and other hardware people that have
moved into software. They often lack significant formal education in
programming or in C. So guidelines here can match that.

All in all, this means MISRA can be useful and appropriate in some
cases, and inappropriate in other cases - they are certainly not
something you'd use for all C programming.

Re: How About Disallowing Assignments In Expressions?

<86wmrc49ph.fsf@linuxsc.com>

  copy mid

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

  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: tr.17687@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Sat, 10 Feb 2024 07:31:38 -0800
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <86wmrc49ph.fsf@linuxsc.com>
References: <uq3s76$28dsr$1@dont-email.me> <uq3t2m$28nj4$1@dont-email.me> <uq41in$2a4jh$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="c20874413056af7bcbd7e84e1693869d";
logging-data="3383391"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/G4AaGrWYWlYKR4q93IBWy9YB2F7rGt9w="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:ARwPx2gemAXRZO2ZoXxCHljqE8Q=
sha1:bOdBoHxaOWqKFnCpgbFXRyfnrTc=
 by: Tim Rentsch - Sat, 10 Feb 2024 15:31 UTC

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

> On Fri, 9 Feb 2024 00:53:42 +0000, Malcolm McLean wrote:
>
>> while( (ch = fgetc(fp)) != EOF)
>>
>> is the idiomatic way of accessing a stream a character by character in
>> C. So you would disallow this.
>
> Yes!

What code would you write to accomplish the same thing, under the
assumption that what you're proposing is adopted?

As long as I'm asking, how would you write it in C as it is now?

Re: How About Disallowing Assignments In Expressions?

<uq8664$37s6n$1@dont-email.me>

  copy mid

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

  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.brown@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Sat, 10 Feb 2024 16:53:39 +0100
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <uq8664$37s6n$1@dont-email.me>
References: <uq3s76$28dsr$1@dont-email.me> <uq4nmb$2hive$6@dont-email.me>
<87r0hlef8q.fsf@nosuchdomain.example.com> <uq6nha$2spqe$3@dont-email.me>
<87jzndc5sq.fsf@nosuchdomain.example.com>
<87fry1c5qo.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 10 Feb 2024 15:53:40 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="94c27d23ea8de2abb521791d5d2342a2";
logging-data="3403991"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19oQRdKSD6dHqZwekWdjyNFZ7/1ON8M2uI="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:G4AhAdpGRBlIMXoYCRuKHxisqDs=
Content-Language: en-GB
In-Reply-To: <87fry1c5qo.fsf@nosuchdomain.example.com>
 by: David Brown - Sat, 10 Feb 2024 15:53 UTC

On 10/02/2024 05:17, Keith Thompson wrote:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>>> On Fri, 09 Feb 2024 09:09:41 -0800, Keith Thompson wrote:
>>>> But it's far too late to fix that in any language called "C".
>>>
>>> I had a look at the MISRA specs, and they say “assignment operators shall
>>> not be used in expressions that yield a boolean value”.
>>
>> I presume they mean expressions used as conditions, but unless they
>> define what they the phrase "boolean value" somwhere, that's not what
>> they wrote.
>
> Editing error.
>
> I presume they mean expressions used as conditions, but unless they
> define what they *mean by* the phrase "boolean value" somwhere, that's
> not what they wrote.
>

In MISRA 1998, the explanation for that rule includes:

"""
Strictly speaking, in C, there is no Boolean type, but there is a
conceptual difference between expressions which return a numeric value
and expressions which return a Boolean value.

If assignments are required then they must be performed separately
outside of any expressions which are effectively of Boolean type.
"""

MISRA regularly uses its own terms that are different from the Standard
C terms, which IMHO is needlessly confusing and inaccurate. Sometimes
these terms are defined, sometimes not. "Boolean" and "Effectively
Boolean value" are not defined anywhere in MISRA 1998.

(And in MISRA 2012 there is the extraordinary, messy, vague and badly
defined idea of "the essential type model" which seems to be what the
MISRA authors wished C had for its types, operators and conversions, but
which is at odds with what C really has.)

In MISRA C 2012, the assignment rule is simpler : "The result of an
assignment operator should not be used".

Re: How About Disallowing Assignments In Expressions?

<uq86e9$37s7s$1@dont-email.me>

  copy mid

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

  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: david.brown@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Sat, 10 Feb 2024 16:58:01 +0100
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <uq86e9$37s7s$1@dont-email.me>
References: <uq3s76$28dsr$1@dont-email.me> <uq4nmb$2hive$6@dont-email.me>
<87r0hlef8q.fsf@nosuchdomain.example.com> <uq6nha$2spqe$3@dont-email.me>
<87sf20o4e2.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 10 Feb 2024 15:58:01 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="94c27d23ea8de2abb521791d5d2342a2";
logging-data="3404028"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19orPcLumESS398gJaWwsLosutjmbKP+Vw="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Z/SxfSVc69DdXUN39Ti15NNcqBM=
In-Reply-To: <87sf20o4e2.fsf@bsb.me.uk>
Content-Language: en-GB
 by: David Brown - Sat, 10 Feb 2024 15:58 UTC

On 10/02/2024 14:06, Ben Bacarisse wrote:
> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>
>> On Fri, 09 Feb 2024 09:09:41 -0800, Keith Thompson wrote:
>>
>>> But it's far too late to fix that in any language called "C".
>>
>> I had a look at the MISRA specs, and they say “assignment operators shall
>> not be used in expressions that yield a boolean value”.
>
> Oddly worded. They can't mean what they say.
>

It says "Assignment operators shall not be used in expressions which
return Boolean values", at least in my copy of MISRA 1998. Of course,
the use of "return" just makes it worse.

They explain with examples:

"""
For example write:

x = y;
if ( x != 0 )
{
foo();
}

and not:

if ( ( x = y ) != 0 )
{
foo();
}

or even worse:

if ( x = y )
{
foo();
}

This helps to avoid getting ‘=’and ‘==’confused, and assists the static
detection of mistakes.
"""

Re: How About Disallowing Assignments In Expressions?

<uq86uh$37s7s$2@dont-email.me>

  copy mid

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

  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.brown@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Sat, 10 Feb 2024 17:06:41 +0100
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <uq86uh$37s7s$2@dont-email.me>
References: <uq3s76$28dsr$1@dont-email.me>
<pan$68183$c20f769a$773bf670$77626466@invalid.invalid>
<uq65j6$2psod$11@dont-email.me>
<pan$26eef$4f4fde86$8b9cd01b$37f2c6db@invalid.invalid>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 10 Feb 2024 16:06:41 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="94c27d23ea8de2abb521791d5d2342a2";
logging-data="3404028"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+/Us0ZQiOvgS0wLcmRNPPIPBr8L6GQIek="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:eaHT6fCh/Fc/kp60tNkU+yPb2JI=
Content-Language: en-GB
In-Reply-To: <pan$26eef$4f4fde86$8b9cd01b$37f2c6db@invalid.invalid>
 by: David Brown - Sat, 10 Feb 2024 16:06 UTC

On 10/02/2024 09:05, Blue-Maned_Hawk wrote:
> Lawrence D'Oliveiro wrote:
>
>> On Fri, 9 Feb 2024 19:47:45 -0000 (UTC), Blue-Maned_Hawk wrote:
>>
>>> There are too many situations where assignment being an expression is a
>>> useful facet of the language; i am not willing to sacrifice that for an
>>> ill-defined ideal of “safety”.
>>
>> If you consider it “ill-defined”, consider the number of people who have
>> developed the habit of writing
>>
>> if (NULL == p) ...
>>
>> instead of the more natural
>>
>> if (p == NULL) ...
>
> Y'know, there's some coding style guide that explicitly states _not_ to do
> those kinds of “yoda comparisons”, but i've never seen any code that
> actually uses them.
>

I have seen them all over the place. They are very common in code
written to MISRA, even though they are not required by the standard. It
is also common in code written by people who have been taught that C is
"dangerous" and you need to write "safe" C like :

if (42 == x) ...

or

if (TRUE == (x < y)) ...

(I'm not making this up.)

Re: How About Disallowing Assignments In Expressions?

<uq8qrg$3padl$12@dont-email.me>

  copy mid

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

  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: How About Disallowing Assignments In Expressions?
Date: Sat, 10 Feb 2024 21:46:24 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <uq8qrg$3padl$12@dont-email.me>
References: <uq3s76$28dsr$1@dont-email.me> <uq4nmb$2hive$6@dont-email.me>
<87r0hlef8q.fsf@nosuchdomain.example.com> <uq6nha$2spqe$3@dont-email.me>
<20240209190146.125@kylheku.com> <uq7vlm$36orr$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 10 Feb 2024 21:46:24 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cb0aecca639ac885e888a888c6c2d7ce";
logging-data="3975605"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/DIl6S1Y7OuFrxax+WVur8"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:SIIp/SooyU+VVE1b70n74ZOaLN4=
 by: Lawrence D'Oliv - Sat, 10 Feb 2024 21:46 UTC

On Sat, 10 Feb 2024 15:02:30 +0100, David Brown wrote:

> All in all, this means MISRA can be useful and appropriate in some
> cases, and inappropriate in other cases - they are certainly not
> something you'd use for all C programming.

Nevertheless, they are based on real-world experience with certain all-
too-common errors with C programming, are they not.

Re: How About Disallowing Assignments In Expressions?

<uq8quh$3padl$13@dont-email.me>

  copy mid

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

  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: How About Disallowing Assignments In Expressions?
Date: Sat, 10 Feb 2024 21:48:01 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <uq8quh$3padl$13@dont-email.me>
References: <uq3s76$28dsr$1@dont-email.me> <uq4nmb$2hive$6@dont-email.me>
<87r0hlef8q.fsf@nosuchdomain.example.com> <uq6nha$2spqe$3@dont-email.me>
<87sf20o4e2.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 10 Feb 2024 21:48:01 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cb0aecca639ac885e888a888c6c2d7ce";
logging-data="3975605"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18UdU2R9ePFCtj/yBzr3N+k"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:BziHrceR5U+VT7Do/41I8KGYmVU=
 by: Lawrence D'Oliv - Sat, 10 Feb 2024 21:48 UTC

On Sat, 10 Feb 2024 13:06:13 +0000, Ben Bacarisse wrote:

> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>
>> I had a look at the MISRA specs, and they say “assignment operators
>> shall not be used in expressions that yield a boolean value”.
>
> Oddly worded. They can't mean what they say.

It is cleverly worded. The idea is obviously to allow chained assignments,
while disallowing doing a test on the value being assigned. The examples
make this clear.

Re: How About Disallowing Assignments In Expressions?

<uq8r1d$3padl$14@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!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: How About Disallowing Assignments In Expressions?
Date: Sat, 10 Feb 2024 21:49:33 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <uq8r1d$3padl$14@dont-email.me>
References: <uq3s76$28dsr$1@dont-email.me> <uq4nmb$2hive$6@dont-email.me>
<87r0hlef8q.fsf@nosuchdomain.example.com> <uq6nha$2spqe$3@dont-email.me>
<87jzndc5sq.fsf@nosuchdomain.example.com>
<87fry1c5qo.fsf@nosuchdomain.example.com> <uq8664$37s6n$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 10 Feb 2024 21:49:33 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cb0aecca639ac885e888a888c6c2d7ce";
logging-data="3975605"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX197wt6OnkJqnDP8TcdQNzLm"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:u7LWohXWIUC9GSEfkbn8zlprhrw=
 by: Lawrence D'Oliv - Sat, 10 Feb 2024 21:49 UTC

On Sat, 10 Feb 2024 16:53:39 +0100, David Brown wrote:

> In MISRA C 2012, the assignment rule is simpler : "The result of an
> assignment operator should not be used".

Interesting. So no more chained assignments?

Python manages to allow these, without allowing assignments to actually
have a value as such.

Of course, Python has its own pitfalls, such as

a = b = []

Re: How About Disallowing Assignments In Expressions?

<87jzncndle.fsf@bsb.me.uk>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.nntp4.net!news.hispagatos.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Sat, 10 Feb 2024 22:45:01 +0000
Organization: A noiseless patient Spider
Lines: 83
Message-ID: <87jzncndle.fsf@bsb.me.uk>
References: <uq3s76$28dsr$1@dont-email.me> <uq4nmb$2hive$6@dont-email.me>
<87r0hlef8q.fsf@nosuchdomain.example.com>
<uq6nha$2spqe$3@dont-email.me> <87sf20o4e2.fsf@bsb.me.uk>
<uq86e9$37s7s$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="c13342fcfa2cdc30d6c9e83b0b27a1c1";
logging-data="89583"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18gNSznpjZoy3wIoMb0Ampu5sQ6phCqZqg="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:7RA/eIH2oOZ5sxxEXrCbusAVK9w=
sha1:7hQqPxjEVH+DgvyNfyr7uaX3cPI=
X-BSB-Auth: 1.ed38fb71a08af464c082.20240210224501GMT.87jzncndle.fsf@bsb.me.uk
 by: Ben Bacarisse - Sat, 10 Feb 2024 22:45 UTC

David Brown <david.brown@hesbynett.no> writes:

> On 10/02/2024 14:06, Ben Bacarisse wrote:
>> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>>
>>> On Fri, 09 Feb 2024 09:09:41 -0800, Keith Thompson wrote:
>>>
>>>> But it's far too late to fix that in any language called "C".
>>>
>>> I had a look at the MISRA specs, and they say “assignment operators shall
>>> not be used in expressions that yield a boolean value”.
>> Oddly worded. They can't mean what they say.
>
> It says "Assignment operators shall not be used in expressions which return
> Boolean values", at least in my copy of MISRA 1998. Of course, the use of
> "return" just makes it worse.
>
> They explain with examples:
>
> """
> For example write:
>
> x = y;
> if ( x != 0 )
> {
> foo();
> }
>
> and not:
>
> if ( ( x = y ) != 0 )

x = y is an expression that yields a value of the type of x (after
lvalue conversion). This is unlikely to be _Bool which (even if they
mean _Bool instead of Boolean) is why I say they can't mean what they
say.

Your later post in reply to someone else explains that they don't mean
what they say though, even a few minutes after reading it, I can't
remember what the clarification was.

> {
> foo();
> }
>
> or even worse:
>
> if ( x = y )
> {
> foo();
> }
>
> This helps to avoid getting ‘=’and ‘==’confused, and assists the static
> detection of mistakes.
> """

These sorts of guides often use silly examples like this. What is the
MIRSA preferred why to write

while ((x = get_the_next_x(...)) != NO_MORE_Xs) {
... use x ...
}

? Presumably they want people to duplicate the call:

x = get_the_next_x(...);
while (x != NO_MORE_Xs) {
... use x ...
x - get_the_next_y(...);
}

or maybe use break:

while (1) {
x = get_the_next_x(...);
if (x != NO_MORE_Xs) break;
... use x ...
}

Neither looks good to me.

--
Ben.


devel / comp.lang.c / Re: How About Disallowing Assignments In Expressions?

Pages:123456789101112131415161718192021
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor