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?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!i2pn.org!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:47:01 +0000
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <87eddkndi2.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>
<uq8quh$3padl$13@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="U2FsdGVkX1+DwKQNVvPUieh0tlaHE81l0N6R7uFOGJU="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:ZWXQk8gMW2HVa5gBaiTgKlQBhJw=
sha1:cyKO/0ZroTpBpdEcL7ES+wl1L8I=
X-BSB-Auth: 1.9d5ba968d8c2a4f527de.20240210224701GMT.87eddkndi2.fsf@bsb.me.uk
 by: Ben Bacarisse - Sat, 10 Feb 2024 22:47 UTC

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

> 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.

See my (corrected) reply to David Brown for why their examples make it
clear that they don't mean what they say.

--
Ben.

Re: How About Disallowing Assignments In Expressions?

<878r3snde1.fsf@bsb.me.uk>

  copy mid

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

  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: Sat, 10 Feb 2024 22:49:26 +0000
Organization: A noiseless patient Spider
Lines: 89
Message-ID: <878r3snde1.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> <87jzncndle.fsf@bsb.me.uk>
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="U2FsdGVkX1/cu6itIs/raCo7HBJvdkpcXWtRbOrbxWI="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:JUKQ75c3QO9ZmUVGRYHjo8wJwKI=
sha1:D0+azDHBOG7wEjX0yaDjCEPtusY=
X-BSB-Auth: 1.034012d356260bc42ace.20240210224926GMT.878r3snde1.fsf@bsb.me.uk
 by: Ben Bacarisse - Sat, 10 Feb 2024 22:49 UTC

Ben Bacarisse <ben.usenet@bsb.me.uk> writes:

> 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.

I need to correct this because (though I am guessing) they probably mean
that the value of the assignment can't be used in the integer-valued
expression whose operator is !=.

> 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.

Re: How About Disallowing Assignments In Expressions?

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

  copy mid

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

  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: Sat, 10 Feb 2024 15:58:55 -0800
Organization: None to speak of
Lines: 22
Message-ID: <87bk8ndg74.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> <87sf20o4e2.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="a3ea5551d1916ca86f611a52355c117b";
logging-data="106934"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1811+Hq33GjZhfeebnRcjbj"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:gMrjeonIbreDx1eVizqWhRGoR4s=
sha1:oc5t8ADF0unxiIoCFat2sLtSFgk=
 by: Keith Thompson - Sat, 10 Feb 2024 23:58 UTC

Ben Bacarisse <ben.usenet@bsb.me.uk> 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”.
>
> Oddly worded. They can't mean what they say.

I'm fairly sure that what they intended to say was that any expression
used as a condition shall not include an assignment operator. It reads
like they couldn't think of the word "condition" and worked around it by
redefining "boolean" (and never telling anyone what it really means).

And apparently a later edition strengthened and simplified the rule to
ban any use of the result of an assignment.

--
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?

<uq93b8$3b6t$2@dont-email.me>

  copy mid

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

  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: bc@freeuk.com (bart)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Sun, 11 Feb 2024 00:11:22 +0000
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <uq93b8$3b6t$2@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> <uq86e9$37s7s$1@dont-email.me>
<87jzncndle.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 11 Feb 2024 00:11:20 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6be035cc50058bcd4371a22b7a653f62";
logging-data="109789"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+mblfD9bMiw/FYWkAnM/do3O5iOnM4fJk="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:m9G4kjnpViEMzw7Ob/LqbHpFU9E=
In-Reply-To: <87jzncndle.fsf@bsb.me.uk>
Content-Language: en-GB
 by: bart - Sun, 11 Feb 2024 00:11 UTC

On 10/02/2024 22:45, Ben Bacarisse wrote:
> David Brown <david.brown@hesbynett.no> writes:
>
>> On 10/02/2024 14:06, Ben Bacarisse wrote:

>> 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.

Another way is the use the gnu extension to put two statements inside
the condition, although when I tried it now it didn't like it:

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

I doubt that would cut any ice with MISRA. You're not technically using
the result of an assignment in an expression, but you're instead putting
entire statements in there!

Re: How About Disallowing Assignments In Expressions?

<uq93it$3g3f$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!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: Sun, 11 Feb 2024 00:15:25 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <uq93it$3g3f$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> <uq86e9$37s7s$1@dont-email.me>
<87jzncndle.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 11 Feb 2024 00:15:25 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="51a39637e14177b0a3992ebbf9b4a091";
logging-data="114799"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18qpm6PW4hzkIDZsd0Ppnjv"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:O2tbtFgbxOUHr4FkAqL1XN56B/Q=
 by: Lawrence D'Oliv - Sun, 11 Feb 2024 00:15 UTC

On Sat, 10 Feb 2024 22:45:01 +0000, Ben Bacarisse wrote:

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

This is the best approach, though in C I generally use “for (;;)” to
indicate “loop forever”. The nice thing is it gracefully generalizes to
more code before (and after) the break, and multiple exits from the loop.

Re: How About Disallowing Assignments In Expressions?

<uq93m2$3g3f$2@dont-email.me>

  copy mid

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

  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: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Sun, 11 Feb 2024 00:17:06 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <uq93m2$3g3f$2@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> <uq86e9$37s7s$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 11 Feb 2024 00:17:06 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="51a39637e14177b0a3992ebbf9b4a091";
logging-data="114799"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Mv4ko0RDZiCmKjQoCaDFx"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:t4LFy76tf8NbaaI3JorXyZZV6+Y=
 by: Lawrence D'Oliv - Sun, 11 Feb 2024 00:17 UTC

On Sat, 10 Feb 2024 16:58:01 +0100, David Brown wrote:

> It says "Assignment operators shall not be used in expressions which
> return Boolean values", at least in my copy of MISRA 1998.

One thing with that wording, it would disallow chained assignments in such
innocuous cases as

a = b = c == d;

since, after all, the expression is returning a boolean.

But this point is moot, since the later revision disallows assignment
chaining completely, anyway.

Re: How About Disallowing Assignments In Expressions?

<8734tzoli4.fsf@bsb.me.uk>

  copy mid

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

  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: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Sun, 11 Feb 2024 01:08:51 +0000
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <8734tzoli4.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> <uq93m2$3g3f$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="956c294dc931e3fb273392ff133791d3";
logging-data="129368"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+UnBbP+mTqG9lqlo0oh5kohlYGcjVM6uQ="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:P+JluwvtBKLa1wGiDrVHYT/NDFA=
sha1:hPyJFkxbvj+7pGKAMxetZWUrjpI=
X-BSB-Auth: 1.2665ced1b72e21f6a2f7.20240211010851GMT.8734tzoli4.fsf@bsb.me.uk
 by: Ben Bacarisse - Sun, 11 Feb 2024 01:08 UTC

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

> On Sat, 10 Feb 2024 16:58:01 +0100, David Brown wrote:
>
>> It says "Assignment operators shall not be used in expressions which
>> return Boolean values", at least in my copy of MISRA 1998.
>
> One thing with that wording, it would disallow chained assignments in such
> innocuous cases as
>
> a = b = c == d;
>
> since, after all, the expression is returning a boolean.

The type of c == d is int, but the value will be either 0 or 1. Is that
what you mean by an expression "returning a boolean" -- an expression of
type in with either 0 or 1 as the value? If so you could have written

a = b = 1;

and made the same claim.

> But this point is moot, since the later revision disallows assignment
> chaining completely, anyway.

--
Ben.

Re: How About Disallowing Assignments In Expressions?

<uq979e$40n1$1@dont-email.me>

  copy mid

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

  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: Sun, 11 Feb 2024 01:18:38 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <uq979e$40n1$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> <uq86e9$37s7s$1@dont-email.me>
<uq93m2$3g3f$2@dont-email.me> <8734tzoli4.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 11 Feb 2024 01:18:38 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="51a39637e14177b0a3992ebbf9b4a091";
logging-data="131809"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ME4C+8gq9wo1R0tuAHvbk"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:QA0Snthv7yEZ/3zpILtw0GScmaQ=
 by: Lawrence D'Oliv - Sun, 11 Feb 2024 01:18 UTC

On Sun, 11 Feb 2024 01:08:51 +0000, Ben Bacarisse wrote:

> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>
>> On Sat, 10 Feb 2024 16:58:01 +0100, David Brown wrote:
>>
>>> It says "Assignment operators shall not be used in expressions which
>>> return Boolean values", at least in my copy of MISRA 1998.
>>
>> One thing with that wording, it would disallow chained assignments in
>> such innocuous cases as
>>
>> a = b = c == d;
>>
>> since, after all, the expression is returning a boolean.
>
> The type of c == d is int, but the value will be either 0 or 1.

That is the only kind of “boolean” C has.

Re: How About Disallowing Assignments In Expressions?

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

  copy mid

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

  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.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Sat, 10 Feb 2024 17:34:51 -0800
Organization: None to speak of
Lines: 29
Message-ID: <87v86vbx6s.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> <87sf20o4e2.fsf@bsb.me.uk>
<uq86e9$37s7s$1@dont-email.me> <uq93m2$3g3f$2@dont-email.me>
<8734tzoli4.fsf@bsb.me.uk> <uq979e$40n1$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="a3ea5551d1916ca86f611a52355c117b";
logging-data="134590"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18hfJGZs3TgqpV4KbJ6FZ5y"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:YB+gvE0ZntFroG06K9ZvIF5pNZI=
sha1:5XpdwV8ZTCulff9xeRVIT4UyXvI=
 by: Keith Thompson - Sun, 11 Feb 2024 01:34 UTC

Lawrence D'Oliveiro <ldo@nz.invalid> writes:
> On Sun, 11 Feb 2024 01:08:51 +0000, Ben Bacarisse wrote:
>> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>>> On Sat, 10 Feb 2024 16:58:01 +0100, David Brown wrote:
>>>> It says "Assignment operators shall not be used in expressions which
>>>> return Boolean values", at least in my copy of MISRA 1998.
>>>
>>> One thing with that wording, it would disallow chained assignments in
>>> such innocuous cases as
>>>
>>> a = b = c == d;
>>>
>>> since, after all, the expression is returning a boolean.
>>
>> The type of c == d is int, but the value will be either 0 or 1.
>
> That is the only kind of “boolean” C has.

No it isn't. C99 added _Bool, which can be called bool if you include
<stdbool.h>. C23 (not yet released) will make bool a keyword, with
_Bool as an alternative spelling.

But the equality and relational operators still yield results of type
int with value 0 or 1.

--
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?

<uq98lm$40n1$6@dont-email.me>

  copy mid

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

  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: Sun, 11 Feb 2024 01:42:14 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <uq98lm$40n1$6@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> <uq86e9$37s7s$1@dont-email.me>
<uq93m2$3g3f$2@dont-email.me> <8734tzoli4.fsf@bsb.me.uk>
<uq979e$40n1$1@dont-email.me> <87v86vbx6s.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 11 Feb 2024 01:42:14 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="51a39637e14177b0a3992ebbf9b4a091";
logging-data="131809"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19cYTs0Z+3MdsLw5kVWVOPp"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:T/4h0/iNhjpi5sMYo1QxhgaJNjY=
 by: Lawrence D'Oliv - Sun, 11 Feb 2024 01:42 UTC

On Sat, 10 Feb 2024 17:34:51 -0800, Keith Thompson wrote:

> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>
>> On Sun, 11 Feb 2024 01:08:51 +0000, Ben Bacarisse wrote:
>>
>>> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>>>
>>>> On Sat, 10 Feb 2024 16:58:01 +0100, David Brown wrote:
>>>>
>>>>> It says "Assignment operators shall not be used in expressions which
>>>>> return Boolean values", at least in my copy of MISRA 1998.
>>>>
>>>> One thing with that wording, it would disallow chained assignments in
>>>> such innocuous cases as
>>>>
>>>> a = b = c == d;
>>>>
>>>> since, after all, the expression is returning a boolean.
>>>
>>> The type of c == d is int, but the value will be either 0 or 1.
>>
>> That is the only kind of “boolean” C has.
>
> No it isn't. C99 added _Bool, which can be called bool if you include
> <stdbool.h>. C23 (not yet released) will make bool a keyword, with
> _Bool as an alternative spelling.
>
> But the equality and relational operators still yield results of type
> int with value 0 or 1.

All just new, different names for what I said: still the only kind of
“boolean” C has.

Re: How About Disallowing Assignments In Expressions?

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

  copy mid

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

  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: Sat, 10 Feb 2024 18:00:57 -0800
Organization: None to speak of
Lines: 37
Message-ID: <87il2vbvza.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> <87sf20o4e2.fsf@bsb.me.uk>
<uq86e9$37s7s$1@dont-email.me> <uq93m2$3g3f$2@dont-email.me>
<8734tzoli4.fsf@bsb.me.uk> <uq979e$40n1$1@dont-email.me>
<87v86vbx6s.fsf@nosuchdomain.example.com>
<uq98lm$40n1$6@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="a3ea5551d1916ca86f611a52355c117b";
logging-data="140583"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19l3PcSZCi/tk35QwNKBLzL"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:QsToecqG+IoL03LVT5zQfjPPwss=
sha1:jyo0A54Mcii0P1xiJ8/NauYPTeo=
 by: Keith Thompson - Sun, 11 Feb 2024 02:00 UTC

Lawrence D'Oliveiro <ldo@nz.invalid> writes:
> On Sat, 10 Feb 2024 17:34:51 -0800, Keith Thompson wrote:
>> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>>> On Sun, 11 Feb 2024 01:08:51 +0000, Ben Bacarisse wrote:
[...]
>>>> The type of c == d is int, but the value will be either 0 or 1.
>>>
>>> That is the only kind of “boolean” C has.
>>
>> No it isn't. C99 added _Bool, which can be called bool if you include
>> <stdbool.h>. C23 (not yet released) will make bool a keyword, with
>> _Bool as an alternative spelling.
>>
>> But the equality and relational operators still yield results of type
>> int with value 0 or 1.
>
> All just new, different names for what I said: still the only kind of
> “boolean” C has.

I can imagine that you're trying to express something that's correct,
but I honestly have no idea what it might be.

C has a boolean type, called "_Bool" or "bool", added in C99. _Bool is
a distinct type, not the same as or compatible with any other type.

Equality and relational operators yield results of type int, not _Bool.

An expression of any scalar type (which includes integer,
floating-point, and pointer types) can be used as a condition.

Assuming you agree with all that, I have no idea what you mean by "the
only kind of “boolean” C has".

--
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?

<uq9m1n$bfj9$1@dont-email.me>

  copy mid

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

  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: Sun, 11 Feb 2024 05:30:31 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <uq9m1n$bfj9$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> <uq86e9$37s7s$1@dont-email.me>
<uq93m2$3g3f$2@dont-email.me> <8734tzoli4.fsf@bsb.me.uk>
<uq979e$40n1$1@dont-email.me> <87v86vbx6s.fsf@nosuchdomain.example.com>
<uq98lm$40n1$6@dont-email.me> <87il2vbvza.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 11 Feb 2024 05:30:31 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="51a39637e14177b0a3992ebbf9b4a091";
logging-data="376425"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+AcNrAiMIFIOyUXdzpq6qD"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:NorTcwM9s9PmNY7ZI9zy0jEtEmo=
 by: Lawrence D'Oliv - Sun, 11 Feb 2024 05:30 UTC

On Sat, 10 Feb 2024 18:00:57 -0800, Keith Thompson wrote:

> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>> On Sat, 10 Feb 2024 17:34:51 -0800, Keith Thompson wrote:
>>> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>>>> On Sun, 11 Feb 2024 01:08:51 +0000, Ben Bacarisse wrote:
> [...]
>>>>> The type of c == d is int, but the value will be either 0 or 1.
>>>>
>>>> That is the only kind of “boolean” C has.
>>>
>>> No it isn't. C99 added _Bool, which can be called bool if you include
>>> <stdbool.h>. C23 (not yet released) will make bool a keyword, with
>>> _Bool as an alternative spelling.
>>>
>>
>> All just new, different names for what I said: still the only kind of
>> “boolean” C has.
>
> I can imagine that you're trying to express something that's correct,
> but I honestly have no idea what it might be.
>
> C has a boolean type, called "_Bool" or "bool", added in C99. _Bool is
> a distinct type, not the same as or compatible with any other type.

No, it is not:

>>> But the equality and relational operators still yield results of type
>>> int with value 0 or 1.

See, no “distinct boolean type”.

Re: How About Disallowing Assignments In Expressions?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.furie.org.uk!usenet.goja.nl.eu.org!weretis.net!feeder8.news.weretis.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: Sat, 10 Feb 2024 21:37:26 -0800
Organization: None to speak of
Lines: 50
Message-ID: <87eddjblyh.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> <87sf20o4e2.fsf@bsb.me.uk>
<uq86e9$37s7s$1@dont-email.me> <uq93m2$3g3f$2@dont-email.me>
<8734tzoli4.fsf@bsb.me.uk> <uq979e$40n1$1@dont-email.me>
<87v86vbx6s.fsf@nosuchdomain.example.com>
<uq98lm$40n1$6@dont-email.me>
<87il2vbvza.fsf@nosuchdomain.example.com>
<uq9m1n$bfj9$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="a3ea5551d1916ca86f611a52355c117b";
logging-data="320402"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/D1cBCpFW0+qBua11qPm9A"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:zjLItBYf0HJLrpAHnnv4/41HDGw=
sha1:ksffjxpxT3NWqQfLYM0JnnD4JeQ=
 by: Keith Thompson - Sun, 11 Feb 2024 05:37 UTC

Lawrence D'Oliveiro <ldo@nz.invalid> writes:
> On Sat, 10 Feb 2024 18:00:57 -0800, Keith Thompson wrote:
>> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>>> On Sat, 10 Feb 2024 17:34:51 -0800, Keith Thompson wrote:
>>>> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>>>>> On Sun, 11 Feb 2024 01:08:51 +0000, Ben Bacarisse wrote:
>> [...]
>>>>>> The type of c == d is int, but the value will be either 0 or 1.
>>>>>
>>>>> That is the only kind of “boolean” C has.
>>>>
>>>> No it isn't. C99 added _Bool, which can be called bool if you include
>>>> <stdbool.h>. C23 (not yet released) will make bool a keyword, with
>>>> _Bool as an alternative spelling.
>>>>
>>>
>>> All just new, different names for what I said: still the only kind of
>>> “boolean” C has.
>>
>> I can imagine that you're trying to express something that's correct,
>> but I honestly have no idea what it might be.
>>
>> C has a boolean type, called "_Bool" or "bool", added in C99. _Bool is
>> a distinct type, not the same as or compatible with any other type.
>
> No, it is not:

Incorrect.

>>>> But the equality and relational operators still yield results of type
>>>> int with value 0 or 1.

Yes, and?

> See, no “distinct boolean type”.

I see. You're simply wrong.

_Bool is a distinct type. Equality and relational operators yield
results of type int, which is not type _Bool.

Again, C has a distinct boolean type *that it doesn't use in some
contexts where it would make sense to do so, for historical reasons*.

Which part of that do you disagree with?

--
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?

<uqa8hc$ufd8$1@dont-email.me>

  copy mid

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

  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.arthur.mclean@gmail.com (Malcolm McLean)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Sun, 11 Feb 2024 10:46:04 +0000
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <uqa8hc$ufd8$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> <uq6dus$2rkfe$1@dont-email.me>
<87y1bso4iv.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 11 Feb 2024 10:46:04 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="deece328de694df64c73ed50e3f940b0";
logging-data="998824"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/w/JQstOQBjYS/6fobyDDaPq58VoSuhcI="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:8bIl+leGy4+KNa0nyen7Ypyc+Vw=
Content-Language: en-GB
In-Reply-To: <87y1bso4iv.fsf@bsb.me.uk>
 by: Malcolm McLean - Sun, 11 Feb 2024 10:46 UTC

On 10/02/2024 13:03, Ben Bacarisse wrote:
> 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.
>
Now is my memory playing tricks on me?

I hae a distinct memory of taking out that bug recently. But all the
changes are kept in git repositories. I've checked the repositories, and
that bug is nowhere to be seen.
--
Check out Basic Algorithms and my other books:
https://www.lulu.com/spotlight/bgy1mm

Re: How About Disallowing Assignments In Expressions?

<uqa9ss$2aerh$1@i2pn2.org>

  copy mid

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

  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: Sun, 11 Feb 2024 12:09:21 +0100
Organization: i2pn2 (i2pn.org)
Message-ID: <uqa9ss$2aerh$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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 11 Feb 2024 11:09:17 -0000 (UTC)
Injection-Info: i2pn2.org;
logging-data="2440049"; 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: <uq5pbq$2nvst$1@dont-email.me>
X-Spam-Checker-Version: SpamAssassin 4.0.0
 by: fir - Sun, 11 Feb 2024 11:09 UTC

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.

it seem clear by me that if someone want upbild c-liek language
(and many people want including me) unicode is needed...
as i previously said yopu need one sign for == and one sign for = (or :=)

this conclusion comes from my study of what is needed and what
could be replaced...this basic set of operators/signs in ansi is to
natrrow and yet those wighs come from outside computer world

imo such operation as assigment is kinda computer specific and = dont
wuite fits

watching the unicode signs and tryin slightly (initially, spending few
minutes on it as for now)

https://en.wikipedia.org/wiki/List_of_Unicode_characters

i didnt find what would fit and what fits best

temporarely i put empty square as example

x▭100, y▭200, z▭x+y

definitelly assuming that i need to drop ansi and find in unicode is
some kind of decision (step up)

Re: How About Disallowing Assignments In Expressions?

<uqaao4$2afv0$1@i2pn2.org>

  copy mid

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

  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: Sun, 11 Feb 2024 12:23:53 +0100
Organization: i2pn2 (i2pn.org)
Message-ID: <uqaao4$2afv0$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> <uqa9ss$2aerh$1@i2pn2.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 11 Feb 2024 11:23:49 -0000 (UTC)
Injection-Info: i2pn2.org;
logging-data="2441184"; 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: <uqa9ss$2aerh$1@i2pn2.org>
 by: fir - Sun, 11 Feb 2024 11:23 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.
>
> it seem clear by me that if someone want upbild c-liek language
> (and many people want including me) unicode is needed...
> as i previously said yopu need one sign for == and one sign for = (or :=)
>
> this conclusion comes from my study of what is needed and what
> could be replaced...this basic set of operators/signs in ansi is to
> natrrow and yet those wighs come from outside computer world
>
> imo such operation as assigment is kinda computer specific and = dont
> wuite fits
>
> watching the unicode signs and tryin slightly (initially, spending few
> minutes on it as for now)
>
> https://en.wikipedia.org/wiki/List_of_Unicode_characters
>
> i didnt find what would fit and what fits best
>
> temporarely i put empty square as example
>
> x▭100, y▭200, z▭x+y
>
> definitelly assuming that i need to drop ansi and find in unicode is
> some kind of decision (step up)
>
>
>
>
>
in fact i also think that more then one sign for asigments is needed

for example this x = foo(y) is something other than this x = y
and it is specially seen when using things liek

x y = foo(a,b,c)
becouse if i want to drep thsi gothic decorators as i name them you got

x y foo a b c

and you could want to denote optionally what is variables ina and
what is variables out and if so the = would look like

x= y= foo <-a <-b <-c thus output of the function probably should be
noted by differnt sign then assigment as it would increase readibility

x' y' foo "a "b "c

i dont knov hovever what signs it should be and there should be find a
way what can be optional

Re: How About Disallowing Assignments In Expressions?

<uqabid$2agt3$1@i2pn2.org>

  copy mid

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

  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: Sun, 11 Feb 2024 12:37:55 +0100
Organization: i2pn2 (i2pn.org)
Message-ID: <uqabid$2agt3$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> <uqa9ss$2aerh$1@i2pn2.org> <uqaao4$2afv0$1@i2pn2.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 11 Feb 2024 11:37:49 -0000 (UTC)
Injection-Info: i2pn2.org;
logging-data="2442147"; 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: <uqaao4$2afv0$1@i2pn2.org>
X-Spam-Checker-Version: SpamAssassin 4.0.0
 by: fir - Sun, 11 Feb 2024 11:37 UTC

fir wrote:
> 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.
>>
>> it seem clear by me that if someone want upbild c-liek language
>> (and many people want including me) unicode is needed...
>> as i previously said yopu need one sign for == and one sign for = (or :=)
>>
>> this conclusion comes from my study of what is needed and what
>> could be replaced...this basic set of operators/signs in ansi is to
>> natrrow and yet those wighs come from outside computer world
>>
>> imo such operation as assigment is kinda computer specific and = dont
>> wuite fits
>>
>> watching the unicode signs and tryin slightly (initially, spending few
>> minutes on it as for now)
>>
>> https://en.wikipedia.org/wiki/List_of_Unicode_characters
>>
>> i didnt find what would fit and what fits best
>>
>> temporarely i put empty square as example
>>
>> x▭100, y▭200, z▭x+y
>>
>> definitelly assuming that i need to drop ansi and find in unicode is
>> some kind of decision (step up)
>>
>>
>>
>>
>>
> in fact i also think that more then one sign for asigments is needed
>
> for example this x = foo(y) is something other than this x = y
> and it is specially seen when using things liek
>
> x y = foo(a,b,c)
> becouse if i want to drep thsi gothic decorators as i name them you got
>
> x y foo a b c
>
> and you could want to denote optionally what is variables ina and
> what is variables out and if so the = would look like
>
> x= y= foo <-a <-b <-c thus output of the function probably should be
> noted by differnt sign then assigment as it would increase readibility
>
> x' y' foo "a "b "c
>
> i dont knov hovever what signs it should be and there should be find a
> way what can be optional
>
>
the decision just to open up unicode can simplify things

for exampel i was wondering back than herdly if

a b c = d e f

should be a 3 element 'vector' or 5 element vector..decision to take
unicode just allow to take one = for 1-element scalar assigment
and soem other sign resembling = for n-element vector assigment
...without it there is some more hard way i probably will even not explore

(and i probably resolved the trouble of what to do with comma "'"

a b, c d e, f

comam should be separator something liek ";" today
those "tuples" separated by space should be vectors, or
particles/particules as i neme them

im presently not sure if some suitable 2-element particules not reserve
for assigments liek

x 1, y 2

means x=1, y=2 but x 1 2 or foo x 1 are 3-element vectors, but im not
sure if this will not break something as it "przeslania" (forget an
englis word, covers?) the 2-element vector syntax i maybe would need

hovever this pure vectors laying in white emptiness of context
of much nothing maybe are worth to cover by something more usable

as some could say this context is wasted

Re: How About Disallowing Assignments In Expressions?

<uqac2h$2ahia$1@i2pn2.org>

  copy mid

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

  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: Sun, 11 Feb 2024 12:46:29 +0100
Organization: i2pn2 (i2pn.org)
Message-ID: <uqac2h$2ahia$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> <uqa9ss$2aerh$1@i2pn2.org> <uqaao4$2afv0$1@i2pn2.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 11 Feb 2024 11:46:26 -0000 (UTC)
Injection-Info: i2pn2.org;
logging-data="2442826"; 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: <uqaao4$2afv0$1@i2pn2.org>
X-Spam-Checker-Version: SpamAssassin 4.0.0
 by: fir - Sun, 11 Feb 2024 11:46 UTC

fir wrote:
> 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.
>>
>> it seem clear by me that if someone want upbild c-liek language
>> (and many people want including me) unicode is needed...
>> as i previously said yopu need one sign for == and one sign for = (or :=)
>>
>> this conclusion comes from my study of what is needed and what
>> could be replaced...this basic set of operators/signs in ansi is to
>> natrrow and yet those wighs come from outside computer world
>>
>> imo such operation as assigment is kinda computer specific and = dont
>> wuite fits
>>
>> watching the unicode signs and tryin slightly (initially, spending few
>> minutes on it as for now)
>>
>> https://en.wikipedia.org/wiki/List_of_Unicode_characters
>>
>> i didnt find what would fit and what fits best
>>
>> temporarely i put empty square as example
>>
>> x▭100, y▭200, z▭x+y
>>
>> definitelly assuming that i need to drop ansi and find in unicode is
>> some kind of decision (step up)
>>
>>
>>
>>
>>
> in fact i also think that more then one sign for asigments is needed
>
> for example this x = foo(y) is something other than this x = y
> and it is specially seen when using things liek
>
> x y = foo(a,b,c)
> becouse if i want to drep thsi gothic decorators as i name them you got
>
> x y foo a b c
>
> and you could want to denote optionally what is variables ina and
> what is variables out and if so the = would look like
>
> x= y= foo <-a <-b <-c thus output of the function probably should be
> noted by differnt sign then assigment as it would increase readibility
>
> x' y' foo "a "b "c
>
> i dont knov hovever what signs it should be and there should be find a
> way what can be optional
>
>

x y foo a b c

optional is not bed also clever editir sein such particles could
set output variables as one color input as another and bold teh function
call name

Re: How About Disallowing Assignments In Expressions?

<uqaf10$v4d8$4@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.furie.org.uk!nntp.terraraq.uk!news.gegeweb.eu!gegeweb.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: Sun, 11 Feb 2024 13:36:48 +0100
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <uqaf10$v4d8$4@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>
<uq8r1d$3padl$14@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 11 Feb 2024 12:36:48 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="5b5b4537e3bb9e65084aa8e461cd54f8";
logging-data="1020328"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18hfDs3jmkS+MG0upRE85n1O4krVG6sdHo="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:aujhRd6NS7GtRrG4dx7ki1HQQ5c=
Content-Language: en-GB
In-Reply-To: <uq8r1d$3padl$14@dont-email.me>
 by: David Brown - Sun, 11 Feb 2024 12:36 UTC

On 10/02/2024 22:49, Lawrence D'Oliveiro wrote:
> 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?
>

Correct.

Chained assignments are used in three ways, I would say :

1. Inappropriately grouping things that are logically separate :

index = sum = 0;

Splitting these makes code clearer.

2. Grouping things to save lines using old-style "declare variables at
the top of the function" code:

int a, b;
...
a = b = 0;

Rather write:

int a = 0;
int b = 0;

3. Cases where grouping really does make sense :

x = y = z = initial_value;

I don't see a problem with case 3, but these are so rare that it is not
a problem if a coding style disallows them.

Re: How About Disallowing Assignments In Expressions?

<uqafh2$v4d8$5@dont-email.me>

  copy mid

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

  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: david.brown@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Sun, 11 Feb 2024 13:45:22 +0100
Organization: A noiseless patient Spider
Lines: 99
Message-ID: <uqafh2$v4d8$5@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> <uq86e9$37s7s$1@dont-email.me>
<87jzncndle.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 11 Feb 2024 12:45:22 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="5b5b4537e3bb9e65084aa8e461cd54f8";
logging-data="1020328"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+IO8Tv+SRs8y7fMqAp4rd/3N8wA4AySEM="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:9bYwuevF3nPcf/BfIqX5M7fmhv4=
Content-Language: en-GB
In-Reply-To: <87jzncndle.fsf@bsb.me.uk>
 by: David Brown - Sun, 11 Feb 2024 12:45 UTC

On 10/02/2024 23:45, Ben Bacarisse wrote:
> 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.
>

To be clear - I am quoting MISRA here, not saying I think it is
necessarily a good idea, or that the MISRA standards explain it well.

(They don't mean "_Bool" here, because that was MISRA 1998, which
considered only C90.)

> 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.

Agreed.

> 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.
>

That's the issue with almost any rule - there are almost always cases
where breaking the rule leads to clearer code (possibly clearer simply
because it is idiomatic, and therefore familiar).

Re: How About Disallowing Assignments In Expressions?

<uqafqn$v4d8$6@dont-email.me>

  copy mid

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

  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: Sun, 11 Feb 2024 13:50:31 +0100
Organization: A noiseless patient Spider
Lines: 72
Message-ID: <uqafqn$v4d8$6@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> <uq86e9$37s7s$1@dont-email.me>
<87jzncndle.fsf@bsb.me.uk> <uq93b8$3b6t$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 11 Feb 2024 12:50:31 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="5b5b4537e3bb9e65084aa8e461cd54f8";
logging-data="1020328"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18q6w2E9rmwxRi0+C/vcK0U1z5OZbGPhVI="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:dFyyYCf2M1jn8mSWY48VEWPJ7jU=
In-Reply-To: <uq93b8$3b6t$2@dont-email.me>
Content-Language: en-GB
 by: David Brown - Sun, 11 Feb 2024 12:50 UTC

On 11/02/2024 01:11, bart wrote:
> On 10/02/2024 22:45, Ben Bacarisse wrote:
>> David Brown <david.brown@hesbynett.no> writes:
>>
>>> On 10/02/2024 14:06, Ben Bacarisse wrote:
>
>>> 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.
>
> Another way is the use the gnu extension to put two statements inside
> the condition, although when I tried it now it didn't like it:
>
>     while ({x = get_the_next_x(...); x != NO_MORE_Xs;}) {...}
>
> I doubt that would cut any ice with MISRA. You're not technically using
> the result of an assignment in an expression, but you're instead putting
> entire statements in there!

MISRA disallows extensions, despite most compilers used by people
writing MISRA code /requiring/ extensions to do the job.

MISRA 1998 starts with these rules :

1. All code shall conform to ISO 9899 standard C, with no extensions
permitted.

2. Code written in languages other than C should only be used if
there is a defined interface standard for object code to which the
compilers/assemblers for both languages conform.

3. Assembly language functions that are called from C should be
written as C functions containing only in-line assembly language,
and in-line assembly language should not be embedded in normal
C code.

So you are only allowed to use C for your code, conforming to standard
C90, without extensions. But you are allowed to use code in other
languages. And you can't use extensions for your compiler, but if you
use assembly functions, they must be in C inline assembly - which
necessitates extensions.

Did I mention that I thought MISRA was a bit mixed up?

Re: How About Disallowing Assignments In Expressions?

<uqafv1$v4d8$7@dont-email.me>

  copy mid

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

  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: david.brown@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Sun, 11 Feb 2024 13:52:49 +0100
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <uqafv1$v4d8$7@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> <uq86e9$37s7s$1@dont-email.me>
<uq93m2$3g3f$2@dont-email.me> <8734tzoli4.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 11 Feb 2024 12:52:49 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="5b5b4537e3bb9e65084aa8e461cd54f8";
logging-data="1020328"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18NxuTSfaOeTu0PTih1+brRZ14jL/6xrkw="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:HpLLOnCNm61nxcGFbylv/WMH9U4=
Content-Language: en-GB
In-Reply-To: <8734tzoli4.fsf@bsb.me.uk>
 by: David Brown - Sun, 11 Feb 2024 12:52 UTC

On 11/02/2024 02:08, Ben Bacarisse wrote:
> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>
>> On Sat, 10 Feb 2024 16:58:01 +0100, David Brown wrote:
>>
>>> It says "Assignment operators shall not be used in expressions which
>>> return Boolean values", at least in my copy of MISRA 1998.
>>
>> One thing with that wording, it would disallow chained assignments in such
>> innocuous cases as
>>
>> a = b = c == d;
>>
>> since, after all, the expression is returning a boolean.
>
> The type of c == d is int, but the value will be either 0 or 1. Is that
> what you mean by an expression "returning a boolean" -- an expression of
> type in with either 0 or 1 as the value?

I think that is what MISRA means when they talk about "essentially
boolean" - but as I mentioned before, they don't define the term at all.
(MISRA 2012 supports C99, and also appears to consider _Bool as
"essentially boolean", despite not defining it.)

Re: How About Disallowing Assignments In Expressions?

<uqag7k$v4d8$8@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!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: Sun, 11 Feb 2024 13:57:23 +0100
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <uqag7k$v4d8$8@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> <uq8quh$3padl$13@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 11 Feb 2024 12:57:24 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="5b5b4537e3bb9e65084aa8e461cd54f8";
logging-data="1020328"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+93BIG9EZ+ZzJVPYYagJvL3qtScuFg6gc="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:1MBSfe+3A2AVDZ39aE8papAnT1E=
Content-Language: en-GB
In-Reply-To: <uq8quh$3padl$13@dont-email.me>
 by: David Brown - Sun, 11 Feb 2024 12:57 UTC

On 10/02/2024 22:48, Lawrence D'Oliveiro wrote:
> 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.

No. It was badly worded. They had been trying to rule out "if (x = y)"
and requiring it to be written "x = y; if (x != 0) ...".

They did not intend to allow chained assignments - they simply didn't
think to rule them out in MISRA 1998. In MISRA 2012, they changed that
to explicitly rule out /any/ use of the value of an assignment expression.

You are attributing a level of sophistication and forethought to the
MISRA authors that they simply did not have.

Re: How About Disallowing Assignments In Expressions?

<uqau5o$11nm8$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!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: Sun, 11 Feb 2024 16:55:20 +0000
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <uqau5o$11nm8$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> <uq86e9$37s7s$1@dont-email.me>
<uq93m2$3g3f$2@dont-email.me> <8734tzoli4.fsf@bsb.me.uk>
<uq979e$40n1$1@dont-email.me> <87v86vbx6s.fsf@nosuchdomain.example.com>
<uq98lm$40n1$6@dont-email.me> <87il2vbvza.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 11 Feb 2024 16:55:20 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="deece328de694df64c73ed50e3f940b0";
logging-data="1105608"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/zvsnTOG939uxHecjtZuAQ5rY4GeM0PnA="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:6uoKHSBcrWk39JIB54eNNUBONz0=
Content-Language: en-GB
In-Reply-To: <87il2vbvza.fsf@nosuchdomain.example.com>
 by: Malcolm McLean - Sun, 11 Feb 2024 16:55 UTC

On 11/02/2024 02:00, Keith Thompson wrote:
> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>> On Sat, 10 Feb 2024 17:34:51 -0800, Keith Thompson wrote:
>>> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>>>> On Sun, 11 Feb 2024 01:08:51 +0000, Ben Bacarisse wrote:
> [...]
>>>>> The type of c == d is int, but the value will be either 0 or 1.
>>>>
>>>> That is the only kind of “boolean” C has.
>>>
>>> No it isn't. C99 added _Bool, which can be called bool if you include
>>> <stdbool.h>. C23 (not yet released) will make bool a keyword, with
>>> _Bool as an alternative spelling.
>>>
>>> But the equality and relational operators still yield results of type
>>> int with value 0 or 1.
>>
>> All just new, different names for what I said: still the only kind of
>> “boolean” C has.
>
> I can imagine that you're trying to express something that's correct,
> but I honestly have no idea what it might be.
>
> C has a boolean type, called "_Bool" or "bool", added in C99. _Bool is
> a distinct type, not the same as or compatible with any other type.
>
> Equality and relational operators yield results of type int, not _Bool.
>
> An expression of any scalar type (which includes integer,
> floating-point, and pointer types) can be used as a condition.
>
> Assuming you agree with all that, I have no idea what you mean by "the
> only kind of “boolean” C has".
>
Other lanaguages were designed with a "boolean" type which had special
rules (bool + bool would either be disallowed or yield 1
if both were true), and was intended to be used wherever a value was
logically either true or false. C didn't and used a int with just
happened to be 1 or 0 for this purpose, and whilst booleans have now
been added, the old system cannot be entirely eliminated and remains.
You can achieve most of the benefits of a boolean type by aliasing "int'
to "bool" and defining "true" and "false", and a lot of C installations
do exactly this.

--
Check out Basic Algorithms and my other books:
https://www.lulu.com/spotlight/bgy1mm

Re: How About Disallowing Assignments In Expressions?

<uqauo4$11vps$1@dont-email.me>

  copy mid

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

  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: david.brown@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: How About Disallowing Assignments In Expressions?
Date: Sun, 11 Feb 2024 18:05:08 +0100
Organization: A noiseless patient Spider
Lines: 65
Message-ID: <uqauo4$11vps$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> <uq86e9$37s7s$1@dont-email.me>
<uq93m2$3g3f$2@dont-email.me> <8734tzoli4.fsf@bsb.me.uk>
<uq979e$40n1$1@dont-email.me> <87v86vbx6s.fsf@nosuchdomain.example.com>
<uq98lm$40n1$6@dont-email.me> <87il2vbvza.fsf@nosuchdomain.example.com>
<uqau5o$11nm8$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 11 Feb 2024 17:05:08 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="5b5b4537e3bb9e65084aa8e461cd54f8";
logging-data="1113916"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+TqJ4gfvRW7uufZRBhjHjmMPh9c1Mh03U="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:vLtBcvtLl1RzU1nle2s8X/AMfho=
Content-Language: en-GB
In-Reply-To: <uqau5o$11nm8$1@dont-email.me>
 by: David Brown - Sun, 11 Feb 2024 17:05 UTC

On 11/02/2024 17:55, Malcolm McLean wrote:
> On 11/02/2024 02:00, Keith Thompson wrote:
>> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>>> On Sat, 10 Feb 2024 17:34:51 -0800, Keith Thompson wrote:
>>>> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>>>>> On Sun, 11 Feb 2024 01:08:51 +0000, Ben Bacarisse wrote:
>> [...]
>>>>>> The type of c == d is int, but the value will be either 0 or 1.
>>>>>
>>>>> That is the only kind of “boolean” C has.
>>>>
>>>> No it isn't.  C99 added _Bool, which can be called bool if you include
>>>> <stdbool.h>.  C23 (not yet released) will make bool a keyword, with
>>>> _Bool as an alternative spelling.
>>>>
>>>> But the equality and relational operators still yield results of type
>>>> int with value 0 or 1.
>>>
>>> All just new, different names for what I said: still the only kind of
>>> “boolean” C has.
>>
>> I can imagine that you're trying to express something that's correct,
>> but I honestly have no idea what it might be.
>>
>> C has a boolean type, called "_Bool" or "bool", added in C99.  _Bool is
>> a distinct type, not the same as or compatible with any other type.
>>
>> Equality and relational operators yield results of type int, not _Bool.
>>
>> An expression of any scalar type (which includes integer,
>> floating-point, and pointer types) can be used as a condition.
>>
>> Assuming you agree with all that, I have no idea what you mean by "the
>> only kind of “boolean” C has".
>>
> Other lanaguages were designed with a "boolean" type which had special
> rules (bool + bool would either be disallowed or yield 1
>  if both were true), and was intended to be used wherever a value was
> logically either true or false. C didn't and used a int with just
> happened to be 1 or 0 for this purpose, and whilst booleans have now
> been added, the old system cannot be entirely eliminated and remains.

Yes, we all know that. (Well, everyone who has learned a bit of C99
knows that.) It's very difficult to change things in a language that
has as much use as C - changing the type of the value of expressions
like "x == y" would have been a breaking change. When C++ was forked
from C, it was able to make such breaking changes - thus "x == y" gives
a bool in C++. But for C, it was too late.

> You can achieve most of the benefits of a boolean type by aliasing "int'
> to "bool" and defining "true" and "false", and a lot of C installations
> do exactly this.
>

No, you can't. That gives you the worst of all worlds.

Use type "bool" when you want a boolean. It is /not/ the same as an
int, or an enumerated type, or an unsigned char, or anything else that
might be used as a "home-made boolean" - it has important additional
characteristics. "Home-made boolean" types might be considered useful
in C90, but not in C99. Recommending them now is bad advice, and
recommending that you do so using the names "bool", "true" and "false"
which conflict with C's real boolean type is extraordinarily silly.


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

Pages:123456789101112131415161718192021
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor