Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

The unfacts, did we have them, are too imprecisely few to warrant our certitude.


devel / comp.lang.c / Re: bart again (UCX64)

SubjectAuthor
* Re: bart again (UCX64)candycane
`* Re: bart again (UCX64)Richard Damon
 `* Re: bart again (UCX64)Keith Thompson
  `* Re: bart again (UCX64)Richard Damon
   `* Re: bart again (UCX64)Keith Thompson
    +* Re: bart again (UCX64)Kaz Kylheku
    |`* Re: bart again (UCX64)David Brown
    | `* Re: bart again (UCX64)Malcolm McLean
    |  +* Re: bart again (UCX64)David Brown
    |  |+* Re: bart again (UCX64)Bart
    |  ||+* Re: bart again (UCX64)David Brown
    |  |||`* Re: bart again (UCX64)Kaz Kylheku
    |  ||| `* Re: bart again (UCX64)David Brown
    |  |||  `* Re: bart again (UCX64)Kaz Kylheku
    |  |||   `* Re: bart again (UCX64)David Brown
    |  |||    +* Re: bart again (UCX64)Bart
    |  |||    |`* Re: bart again (UCX64)David Brown
    |  |||    | `* Re: bart again (UCX64)Bart
    |  |||    |  `- Re: bart again (UCX64)David Brown
    |  |||    `* Re: bart again (UCX64)Kaz Kylheku
    |  |||     `- Re: bart again (UCX64)David Brown
    |  ||`* Re: bart again (UCX64)Kaz Kylheku
    |  || `- Re: bart again (UCX64)David Brown
    |  |+* Re: bart again (UCX64)Malcolm McLean
    |  ||`* Re: bart again (UCX64)David Brown
    |  || `* Re: bart again (UCX64)Malcolm McLean
    |  ||  +* Re: bart again (UCX64)Ben Bacarisse
    |  ||  |`* Re: bart again (UCX64)Malcolm McLean
    |  ||  | `- Re: bart again (UCX64)Ben Bacarisse
    |  ||  `* Re: bart again (UCX64)David Brown
    |  ||   `* Re: bart again (UCX64)David Brown
    |  ||    +- Re: bart again (UCX64)Chris M. Thomasson
    |  ||    +* Re: bart again (UCX64)Malcolm McLean
    |  ||    |`* Re: bart again (UCX64)David Brown
    |  ||    | `* Re: bart again (UCX64)Malcolm McLean
    |  ||    |  `* Re: bart again (UCX64)David Brown
    |  ||    |   +* Re: bart again (UCX64)Bart
    |  ||    |   |`- Re: bart again (UCX64)David Brown
    |  ||    |   +- Re: bart again (UCX64)Kaz Kylheku
    |  ||    |   +- Re: bart again (UCX64)David Brown
    |  ||    |   `- Re: bart again (UCX64)Kaz Kylheku
    |  ||    `* Re: bart again (UCX64)Bart
    |  ||     +* Re: bart again (UCX64)Malcolm McLean
    |  ||     |`* Re: bart again (UCX64)Kaz Kylheku
    |  ||     | `- Re: bart again (UCX64)Malcolm McLean
    |  ||     +- Re: bart again (UCX64)David Brown
    |  ||     `* Re: bart again (UCX64)Ben Bacarisse
    |  ||      +* Re: bart again (UCX64)Bart
    |  ||      |+- Re: bart again (UCX64)David Brown
    |  ||      |`* Re: bart again (UCX64)Ben Bacarisse
    |  ||      | `* Re: bart again (UCX64)Bart
    |  ||      |  +* Re: bart again (UCX64)Scott Lurndal
    |  ||      |  |`- Re: bart again (UCX64)David Brown
    |  ||      |  `- Re: bart again (UCX64)Ben Bacarisse
    |  ||      `* Re: bart again (UCX64)Malcolm McLean
    |  ||       +* Re: bart again (UCX64)Ben Bacarisse
    |  ||       |+* Re: bart again (UCX64)Bart
    |  ||       ||+* Re: bart again (UCX64)Malcolm McLean
    |  ||       |||`* Re: bart again (UCX64)Scott Lurndal
    |  ||       ||| `* Re: bart again (UCX64)Bart
    |  ||       |||  +- Re: bart again (UCX64)Richard Damon
    |  ||       |||  +- Re: bart again (UCX64)Scott Lurndal
    |  ||       |||  `* Re: bart again (UCX64)Ben Bacarisse
    |  ||       |||   `* Re: bart again (UCX64)Bart
    |  ||       |||    `* Re: bart again (UCX64)Ben Bacarisse
    |  ||       |||     `- Re: bart again (UCX64)Bart
    |  ||       ||`* Re: bart again (UCX64)Ben Bacarisse
    |  ||       || `* Re: bart again (UCX64)Malcolm McLean
    |  ||       ||  `* Re: bart again (UCX64)Ben Bacarisse
    |  ||       ||   +* Re: bart again (UCX64)Bart
    |  ||       ||   |+* Re: bart again (UCX64)David Brown
    |  ||       ||   ||`* Re: bart again (UCX64)Ben Bacarisse
    |  ||       ||   || +* Re: bart again (UCX64)David Brown
    |  ||       ||   || |`- Re: bart again (UCX64)David Brown
    |  ||       ||   || `* Re: bart again (UCX64)Tim Rentsch
    |  ||       ||   ||  `- Re: bart again (UCX64)Ben Bacarisse
    |  ||       ||   |`* Re: bart again (UCX64)Ben Bacarisse
    |  ||       ||   | +- Re: bart again (UCX64)Ben Bacarisse
    |  ||       ||   | `- Re: bart again (UCX64)Tim Rentsch
    |  ||       ||   `* Re: bart again (UCX64)Malcolm McLean
    |  ||       ||    +* Re: bart again (UCX64)Scott Lurndal
    |  ||       ||    |`* Re: bart again (UCX64)Malcolm McLean
    |  ||       ||    | `* Re: bart again (UCX64)Scott Lurndal
    |  ||       ||    |  +* Re: bart again (UCX64)David Brown
    |  ||       ||    |  |`* Re: bart again (UCX64)David Brown
    |  ||       ||    |  | `- Re: bart again (UCX64)David Brown
    |  ||       ||    |  `* Re: bart again (UCX64)David Brown
    |  ||       ||    |   `* Re: bart again (UCX64)Malcolm McLean
    |  ||       ||    |    `* Re: bart again (UCX64)David Brown
    |  ||       ||    |     +* Re: bart again (UCX64)Scott Lurndal
    |  ||       ||    |     |+* Re: bart again (UCX64)James Kuyper
    |  ||       ||    |     ||`* Re: bart again (UCX64)Kaz Kylheku
    |  ||       ||    |     || +* [meta] spam in threadMalcolm McLean
    |  ||       ||    |     || |+* Re: [meta] spam in threadKaz Kylheku
    |  ||       ||    |     || ||`- Re: [meta] spam in threadMalcolm McLean
    |  ||       ||    |     || |`- Re: [meta] spam in threadDavid Brown
    |  ||       ||    |     || `- Re: bart again (UCX64)Ben Bacarisse
    |  ||       ||    |     |`* Re: bart again (UCX64)Tim Rentsch
    |  ||       ||    |     | `* Re: bart again (UCX64)Keith Thompson
    |  ||       ||    |     |  `* Re: bart again (UCX64)Tim Rentsch
    |  ||       ||    |     |   +- Re: bart again (UCX64)Chris M. Thomasson
    |  ||       ||    |     |   `* Re: bart again (UCX64)Keith Thompson
    |  ||       ||    |     `* Re: bart again (UCX64)Malcolm McLean
    |  ||       ||    `* Re: bart again (UCX64)Ben Bacarisse
    |  ||       |+- Re: bart again (UCX64)Ben Bacarisse
    |  ||       |`- Re: bart again (UCX64)David Brown
    |  ||       `* Re: bart again (UCX64)David Brown
    |  |`* Re: bart again (UCX64)Kaz Kylheku
    |  `* Re: bart again (UCX64)Scott Lurndal
    +- Re: bart again (UCX64)David Brown
    `- Re: bart again (UCX64)Richard Damon

Pages:12345
Re: bart again (UCX64)

<1262755563@f172.n1.z21.fsxnet>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.bbs.nz!.POSTED.agency.bbs.nz!not-for-mail
From: candyc...@f172.n1.z21.fsxnet (candycane)
Newsgroups: comp.lang.c
Subject: Re: bart again (UCX64)
Date: Wed, 06 Sep 2023 19:53:56 +1300
Organization: fsxNet Usenet Gateway
Message-ID: <1262755563@f172.n1.z21.fsxnet>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Info: news.bbs.nz; posting-host="8IWYKlztXHa0+IViEdY46zrq8kpk7dC9fTbT74JiSDQ";
logging-data="3936"; mail-complaints-to="abuse@news.bbs.nz"
User-Agent: VSoup v1.2.9.47Beta [95/NT]
X-MailConverter: SoupGate-Win32 v1.05
X-Comment-To: Kaz Kylheku
 by: candycane - Wed, 6 Sep 2023 06:53 UTC

KK> This doesn't:

KK> int fred(void)
KK> {
KK> while (1) {

KK> }
KK> }

KK> The previous one will be a nuisance diagnosic since the always_true
KK> function always returns true.

KK> If the belief is correct, why not restructure the code:

KK> int fred(void)
KK> {
KK> extern int always_true(void);

KK> for (;;) {
KK> always_true(); // call for its side effect only

KK> }
KK> }

I may be reading this wrong, but aren't you getting into the Halting Problem at
this point?

---------------
user <candycane> is generated from /dev/urandom

.... Discover the recipes you are using and abandon them
___ MultiMail/Linux v0.52

Re: bart again (UCX64)

<A5pKM.1180698$TPw2.694138@fx17.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.1d4.us!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx17.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: bart again (UCX64)
Content-Language: en-US
Newsgroups: comp.lang.c
References: <1262755563@f172.n1.z21.fsxnet>
From: Rich...@Damon-Family.org (Richard Damon)
In-Reply-To: <1262755563@f172.n1.z21.fsxnet>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 42
Message-ID: <A5pKM.1180698$TPw2.694138@fx17.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Thu, 7 Sep 2023 12:00:48 -0700
X-Received-Bytes: 1946
 by: Richard Damon - Thu, 7 Sep 2023 19:00 UTC

On 9/5/23 11:53 PM, candycane wrote:
> KK> This doesn't:
>
> KK> int fred(void)
> KK> {
> KK> while (1) {
>
> KK> }
> KK> }
>
> KK> The previous one will be a nuisance diagnosic since the always_true
> KK> function always returns true.
>
> KK> If the belief is correct, why not restructure the code:
>
> KK> int fred(void)
> KK> {
> KK> extern int always_true(void);
>
> KK> for (;;) {
> KK> always_true(); // call for its side effect only
>
> KK> }
> KK> }
>
> I may be reading this wrong, but aren't you getting into the Halting Problem at
> this point?
>

Fulling solving the problem would be the Halting Problem, but there are
shortcuts that can get the vast majority.

Mark functions that don't ever return with -Noreturn or [[noreturn]] (or
an equivalent).

Assume loops with a non-constant control expression will at some point
terminate (yes, this isn't strictly true, but is a reasonable
assumption, and is made elsewhere in the standard).

Since the above program has a for loop with an always true condition,
that can be assumed never to end (since there is no "break" in the loop).

Re: bart again (UCX64)

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

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: bart again (UCX64)
Date: Thu, 07 Sep 2023 16:33:51 -0700
Organization: None to speak of
Lines: 90
Message-ID: <87h6o51rts.fsf@nosuchdomain.example.com>
References: <1262755563@f172.n1.z21.fsxnet>
<A5pKM.1180698$TPw2.694138@fx17.iad>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="642c1896bc45859cf8881c4aaab47004";
logging-data="3328827"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Lvq+ff/xDVcxTIVQx+owf"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:ItMZrIZazxpvXpP6lRxbQxQt+Ik=
sha1:EIrkT/Nn3Jr9VABRUHR6+Yd1VwQ=
 by: Keith Thompson - Thu, 7 Sep 2023 23:33 UTC

Richard Damon <Richard@Damon-Family.org> writes:
> On 9/5/23 11:53 PM, candycane wrote:
>> KK> This doesn't:
>> KK> int fred(void)
>> KK> {
>> KK> while (1) {
>> KK> }
>> KK> }
>> KK> The previous one will be a nuisance diagnosic since the
>> always_true
>> KK> function always returns true.
>> KK> If the belief is correct, why not restructure the code:
>> KK> int fred(void)
>> KK> {
>> KK> extern int always_true(void);
>> KK> for (;;) {
>> KK> always_true(); // call for its side effect only
>> KK> }
>> KK> }
>> I may be reading this wrong, but aren't you getting into the Halting
>> Problem at this point?
>
> Fulling solving the problem would be the Halting Problem, but there
> are shortcuts that can get the vast majority.
>
> Mark functions that don't ever return with -Noreturn or [[noreturn]]
> (or an equivalent).
>
> Assume loops with a non-constant control expression will at some point
> terminate (yes, this isn't strictly true, but is a reasonable
> assumption, and is made elsewhere in the standard).
>
> Since the above program has a for loop with an always true condition,
> that can be assumed never to end (since there is no "break" in the
> loop).

It's not necessary to assume that such loops always terminate. Just
don't assume anything one way or the other.

For example:

int fred(void) {
while (1) {
;
}
}

Since the condition is a constant expression, a reasonably clever
compiler can prove that the closing } is unreachable, so no warning is
necessary. But:

int barney(void) {
while (some_function()) {
;
}
}

Since the condition is not constant, the compiler doesn't know whether
the closing } is reachable. If, as I've suggested, C were to adopt the
C# rules, a diagnostic message would be mandatory, because the closing }
*might* be reached. (Even if the compiler is able to determine that
some_function() always returns 1, because it's defined in the same
translation unit, the diagnostic message would still be required.)

In other words, define a straightforward set of rules for determining
whether a point in the code (particularly the closing } of a non-void
function other than main) is potentially reachable, rules that do not
make any assumptions about non-constant values.

Such a change to C would break some existing code. That's absolutely a
valid reason to oppose it. On the other hand, every major edition of
the C standard has broken some existing code, and compilers have always
supported older versions and/or used non-fatal warnings, so such code
would not be *fatally* broken.

With the C# rules, there are some unavoidable false positives, such as:

int sign(int n) {
if (n < 0) return -1;
if (n == 0) return 0;
if (n > 0) return 1;
}

which are fairly easy to "fix". There are, if I'm not mistaken, no
false negatives.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

Re: bart again (UCX64)

<GWwKM.320358$uLJb.75975@fx41.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!feeder.erje.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx41.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: bart again (UCX64)
Newsgroups: comp.lang.c
References: <1262755563@f172.n1.z21.fsxnet>
<A5pKM.1180698$TPw2.694138@fx17.iad>
<87h6o51rts.fsf@nosuchdomain.example.com>
From: Rich...@Damon-Family.org (Richard Damon)
Content-Language: en-US
In-Reply-To: <87h6o51rts.fsf@nosuchdomain.example.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 121
Message-ID: <GWwKM.320358$uLJb.75975@fx41.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Thu, 7 Sep 2023 20:55:17 -0700
X-Received-Bytes: 5458
 by: Richard Damon - Fri, 8 Sep 2023 03:55 UTC

On 9/7/23 4:33 PM, Keith Thompson wrote:
> Richard Damon <Richard@Damon-Family.org> writes:
>> On 9/5/23 11:53 PM, candycane wrote:
>>> KK> This doesn't:
>>> KK> int fred(void)
>>> KK> {
>>> KK> while (1) {
>>> KK> }
>>> KK> }
>>> KK> The previous one will be a nuisance diagnosic since the
>>> always_true
>>> KK> function always returns true.
>>> KK> If the belief is correct, why not restructure the code:
>>> KK> int fred(void)
>>> KK> {
>>> KK> extern int always_true(void);
>>> KK> for (;;) {
>>> KK> always_true(); // call for its side effect only
>>> KK> }
>>> KK> }
>>> I may be reading this wrong, but aren't you getting into the Halting
>>> Problem at this point?
>>
>> Fulling solving the problem would be the Halting Problem, but there
>> are shortcuts that can get the vast majority.
>>
>> Mark functions that don't ever return with -Noreturn or [[noreturn]]
>> (or an equivalent).
>>
>> Assume loops with a non-constant control expression will at some point
>> terminate (yes, this isn't strictly true, but is a reasonable
>> assumption, and is made elsewhere in the standard).
>>
>> Since the above program has a for loop with an always true condition,
>> that can be assumed never to end (since there is no "break" in the
>> loop).
>
> It's not necessary to assume that such loops always terminate. Just
> don't assume anything one way or the other.

Except that if you want to make falling off the end of an non-void
function an error, you can't do that.

Note, from 6.8.5 p6 which states (using N2596):

An iteration statement may be assumed by the implementation to terminate
if its controlling expression is not a constant expression,171) and none
of the following operations are performed in its body, controlling
expression or (in the case of a for statement) its expression-3:172)
— input/output operations
— accessing a volatile object
— synchronization or atomic operations.

This is a rule that allows optimizations to remove a loop that has no
external effect. A similar rule could be used to determine if the end of
the function is potentially reachable.

>
> For example:
>
> int fred(void) {
> while (1) {
> ;
> }
> }
>
> Since the condition is a constant expression, a reasonably clever
> compiler can prove that the closing } is unreachable, so no warning is
> necessary. But:
>
> int barney(void) {
> while (some_function()) {
> ;
> }
> }
>
> Since the condition is not constant, the compiler doesn't know whether
> the closing } is reachable. If, as I've suggested, C were to adopt the
> C# rules, a diagnostic message would be mandatory, because the closing }
> *might* be reached. (Even if the compiler is able to determine that
> some_function() always returns 1, because it's defined in the same
> translation unit, the diagnostic message would still be required.)

Right, because we need to define the level of effort the compiler needs
to do. And it should avoid "surprizes" as much as possible.

>
> In other words, define a straightforward set of rules for determining
> whether a point in the code (particularly the closing } of a non-void
> function other than main) is potentially reachable, rules that do not
> make any assumptions about non-constant values.
>

Right, and using the existing "rule" about loops with non-constant
control expressions makes the most sense.

> Such a change to C would break some existing code. That's absolutely a
> valid reason to oppose it. On the other hand, every major edition of
> the C standard has broken some existing code, and compilers have always
> supported older versions and/or used non-fatal warnings, so such code
> would not be *fatally* broken.
>
> With the C# rules, there are some unavoidable false positives, such as:
>
> int sign(int n) {
> if (n < 0) return -1;
> if (n == 0) return 0;
> if (n > 0) return 1;
> }
>
> which are fairly easy to "fix". There are, if I'm not mistaken, no
> false negatives.
>

Right. But make the function take a double instead of an int, and it CAN
fall through (on some implementations) since there exist double values
that are none of >0, <0 or == 0.

One option would be to allow an [[unreachable]] attribute to mark that
you can't get here, even if the base rules don't prove it, and leave the
results Undefined if you somehow do get there.

Re: bart again (UCX64)

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

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: bart again (UCX64)
Date: Thu, 07 Sep 2023 22:16:28 -0700
Organization: None to speak of
Lines: 145
Message-ID: <87y1hhmehf.fsf@nosuchdomain.example.com>
References: <1262755563@f172.n1.z21.fsxnet>
<A5pKM.1180698$TPw2.694138@fx17.iad>
<87h6o51rts.fsf@nosuchdomain.example.com>
<GWwKM.320358$uLJb.75975@fx41.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="642c1896bc45859cf8881c4aaab47004";
logging-data="3524126"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/g6gpVh30WhxKBCBGJLxO+"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:yd3ydHvqT5xg4oan3qhsLwgBhH0=
sha1:bkiAsk6lJ8rGUaObfWWCzT0f4Ss=
 by: Keith Thompson - Fri, 8 Sep 2023 05:16 UTC

Richard Damon <Richard@Damon-Family.org> writes:
> On 9/7/23 4:33 PM, Keith Thompson wrote:
>> Richard Damon <Richard@Damon-Family.org> writes:
>>> On 9/5/23 11:53 PM, candycane wrote:
>>>> KK> This doesn't:
>>>> KK> int fred(void)
>>>> KK> {
>>>> KK> while (1) {
>>>> KK> }
>>>> KK> }
>>>> KK> The previous one will be a nuisance diagnosic since the
>>>> always_true
>>>> KK> function always returns true.
>>>> KK> If the belief is correct, why not restructure the code:
>>>> KK> int fred(void)
>>>> KK> {
>>>> KK> extern int always_true(void);
>>>> KK> for (;;) {
>>>> KK> always_true(); // call for its side effect only
>>>> KK> }
>>>> KK> }
>>>> I may be reading this wrong, but aren't you getting into the Halting
>>>> Problem at this point?
>>>
>>> Fulling solving the problem would be the Halting Problem, but there
>>> are shortcuts that can get the vast majority.
>>>
>>> Mark functions that don't ever return with -Noreturn or [[noreturn]]
>>> (or an equivalent).
>>>
>>> Assume loops with a non-constant control expression will at some point
>>> terminate (yes, this isn't strictly true, but is a reasonable
>>> assumption, and is made elsewhere in the standard).
>>>
>>> Since the above program has a for loop with an always true condition,
>>> that can be assumed never to end (since there is no "break" in the
>>> loop).
>> It's not necessary to assume that such loops always terminate. Just
>> don't assume anything one way or the other.
>
> Except that if you want to make falling off the end of an non-void
> function an error, you can't do that.
>
> Note, from 6.8.5 p6 which states (using N2596):
>
> An iteration statement may be assumed by the implementation to
> terminate if its controlling expression is not a constant
> expression,171) and none of the following operations are performed in
> its body, controlling expression or (in the case of a for statement)
> its expression-3:172)
> — input/output operations
> — accessing a volatile object
> — synchronization or atomic operations.
>
> This is a rule that allows optimizations to remove a loop that has no
> external effect. A similar rule could be used to determine if the end
> of the function is potentially reachable.

That does complicate things. Note that currently an implementation is
allowed but not required to "assume" that the loop terminates.
Currently, the standard never requires control flow analysis to
determine whether a constraint is violated.

I'm not sure what the best solution is. I'd like to say that 6.8.5p6
should be ignored when determining whether a diagnostic is required for
potentially reaching a closing }.

Full disclosure: I really dislike that statement in the standard, both
because of its semantics and because it's written to permit an
implementation to "assume" certain things rather than in terms of
permitted behavior.

>> For example:
>> int fred(void) {
>> while (1) {
>> ;
>> }
>> }
>> Since the condition is a constant expression, a reasonably clever
>> compiler can prove that the closing } is unreachable, so no warning is
>> necessary. But:
>> int barney(void) {
>> while (some_function()) {
>> ;
>> }
>> }
>> Since the condition is not constant, the compiler doesn't know
>> whether
>> the closing } is reachable. If, as I've suggested, C were to adopt the
>> C# rules, a diagnostic message would be mandatory, because the closing }
>> *might* be reached. (Even if the compiler is able to determine that
>> some_function() always returns 1, because it's defined in the same
>> translation unit, the diagnostic message would still be required.)
>
> Right, because we need to define the level of effort the compiler
> needs to do. And it should avoid "surprizes" as much as possible.
>
>> In other words, define a straightforward set of rules for
>> determining
>> whether a point in the code (particularly the closing } of a non-void
>> function other than main) is potentially reachable, rules that do not
>> make any assumptions about non-constant values.
>>
>
> Right, and using the existing "rule" about loops with non-constant
> control expressions makes the most sense.
>
>> Such a change to C would break some existing code. That's absolutely a
>> valid reason to oppose it. On the other hand, every major edition of
>> the C standard has broken some existing code, and compilers have always
>> supported older versions and/or used non-fatal warnings, so such code
>> would not be *fatally* broken.
>> With the C# rules, there are some unavoidable false positives, such
>> as:
>> int sign(int n) {
>> if (n < 0) return -1;
>> if (n == 0) return 0;
>> if (n > 0) return 1;
>> }
>> which are fairly easy to "fix". There are, if I'm not mistaken, no
>> false negatives.
>
> Right. But make the function take a double instead of an int, and it
> CAN fall through (on some implementations) since there exist double
> values that are none of >0, <0 or == 0.

That's a different function. I wrote the sign() function above to make
the point I wanted to make.

> One option would be to allow an [[unreachable]] attribute to mark that
> you can't get here, even if the base rules don't prove it, and leave
> the results Undefined if you somehow do get there.

I like it. It's similar to the /*NOTREACHED*/ comment recognized by
many lint implementations.

It could be added *instead* of requiring reachability analysis, and a
programmer could add [[unreachable]] before the closing } of a non-void
function. But adding the requirement I propose would catch errors made
by programmers who don't do that.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

Re: bart again (UCX64)

<20230907235623.619@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: bart again (UCX64)
Date: Fri, 8 Sep 2023 07:09:24 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 68
Message-ID: <20230907235623.619@kylheku.com>
References: <1262755563@f172.n1.z21.fsxnet>
<A5pKM.1180698$TPw2.694138@fx17.iad>
<87h6o51rts.fsf@nosuchdomain.example.com>
<GWwKM.320358$uLJb.75975@fx41.iad>
<87y1hhmehf.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 8 Sep 2023 07:09:24 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="373a38b19466183e0f188ea812ab8873";
logging-data="3550885"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Iam50ciuHRoRaelLAbwhaXbzUM76cUJQ="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:8sYjkxxT5s+shQjJBzIVueU2Hb4=
 by: Kaz Kylheku - Fri, 8 Sep 2023 07:09 UTC

On 2023-09-08, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
> Richard Damon <Richard@Damon-Family.org> writes:
>> Note, from 6.8.5 p6 which states (using N2596):
>>
>> An iteration statement may be assumed by the implementation to
>> terminate if its controlling expression is not a constant
>> expression,171) and none of the following operations are performed in
>> its body, controlling expression or (in the case of a for statement)
>> its expression-3:172)
>> — input/output operations
>> — accessing a volatile object
>> — synchronization or atomic operations.
>>
>> This is a rule that allows optimizations to remove a loop that has no
>> external effect. A similar rule could be used to determine if the end
>> of the function is potentially reachable.
>
> That does complicate things. Note that currently an implementation is
> allowed but not required to "assume" that the loop terminates.
> Currently, the standard never requires control flow analysis to
> determine whether a constraint is violated.

I don't understand the problem. For diagnosing suspected situations
of the end of the function being reached, we want to assume as much
as possible that loops terminate, unless it's obvious otherwise.

Since the above allows the implementation to assume that a loop with
a non-constant controlling expression, and certain other attributes,
terminates, that is compatible; it's what you would want to assume
about that loop when looking whether to apply the diagnostic.

If such a loop precedes the end of the function, and is diagnosed
under a constraint rule, it doesn't matter that it's also optimized
away.

>> One option would be to allow an [[unreachable]] attribute to mark that
>> you can't get here, even if the base rules don't prove it, and leave
>> the results Undefined if you somehow do get there.
>
> I like it. It's similar to the /*NOTREACHED*/ comment recognized by
> many lint implementations.
>
> It could be added *instead* of requiring reachability analysis, and a
> programmer could add [[unreachable]] before the closing } of a non-void
> function. But adding the requirement I propose would catch errors made
> by programmers who don't do that.

The problem with unreachable is that it's a double edged sword.
Here we are thinking of how it helps with diagnosis.

However, it will end up defined as a statement whose purpose is to
invoke undefined behavior. I.e. if [[unreachable]] is reached,
the behavior is undefined, and that's how it works. The assumption
that the program is free of undefined behavior means that no
[[unreachable]] is reached.

Today, an abort() call serves as an expected unreachable point
which has a defined behavior.

If [[unreachable]] were defined as requiring a run-time diagnostic
and termination if it is reached, rather than invoking UB, it would be
more or less the same as abort(); little point in adding it.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: bart again (UCX64)

<udek5q$3cm04$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: bart again (UCX64)
Date: Fri, 8 Sep 2023 09:57:46 +0200
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <udek5q$3cm04$1@dont-email.me>
References: <1262755563@f172.n1.z21.fsxnet>
<A5pKM.1180698$TPw2.694138@fx17.iad>
<87h6o51rts.fsf@nosuchdomain.example.com> <GWwKM.320358$uLJb.75975@fx41.iad>
<87y1hhmehf.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 8 Sep 2023 07:57:46 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="df8021775a6f8b7b93acd6c5303e221a";
logging-data="3561476"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Ssudp7bWNiKrSag3bJQYxk8MbbS+d6xw="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:xHF/8LTp/zxPtmqAFda3xbIrLIQ=
In-Reply-To: <87y1hhmehf.fsf@nosuchdomain.example.com>
Content-Language: en-GB
 by: David Brown - Fri, 8 Sep 2023 07:57 UTC

On 08/09/2023 07:16, Keith Thompson wrote:
> Richard Damon <Richard@Damon-Family.org> writes:

>> One option would be to allow an [[unreachable]] attribute to mark that
>> you can't get here, even if the base rules don't prove it, and leave
>> the results Undefined if you somehow do get there.
>
> I like it. It's similar to the /*NOTREACHED*/ comment recognized by
> many lint implementations.
>

Even better, IMHO, would be a clearly named function (or function-like
macro) to indicate unreachable code. Fortunately for me, C23 has
already thought of that!

<https://en.cppreference.com/w/c/program/unreachable>

Until C23 comes out, many of us can use "__builtin_unreachable()" in
gcc, clang, icc, etc., or "__assume(false))" in MSVC.

> It could be added *instead* of requiring reachability analysis, and a
> programmer could add [[unreachable]] before the closing } of a non-void
> function. But adding the requirement I propose would catch errors made
> by programmers who don't do that.
>

Why not have both? Each solution is useful in situations where the
other is not.

Re: bart again (UCX64)

<udeksu$3crce$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: bart again (UCX64)
Date: Fri, 8 Sep 2023 10:10:05 +0200
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <udeksu$3crce$1@dont-email.me>
References: <1262755563@f172.n1.z21.fsxnet>
<A5pKM.1180698$TPw2.694138@fx17.iad>
<87h6o51rts.fsf@nosuchdomain.example.com> <GWwKM.320358$uLJb.75975@fx41.iad>
<87y1hhmehf.fsf@nosuchdomain.example.com> <20230907235623.619@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 8 Sep 2023 08:10:06 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="df8021775a6f8b7b93acd6c5303e221a";
logging-data="3566990"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ulv0kWqi+C7gBtJb1Vte4zeXarPFdmmI="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:WOfJkU8BJ5jFD1Z3we2qYEcH09k=
Content-Language: en-GB
In-Reply-To: <20230907235623.619@kylheku.com>
 by: David Brown - Fri, 8 Sep 2023 08:10 UTC

On 08/09/2023 09:09, Kaz Kylheku wrote:

> The problem with unreachable is that it's a double edged sword.
> Here we are thinking of how it helps with diagnosis.

Many features of C are double-edged swords.

(This has always struck me as a silly idiom in English, given that for
straight swords, a double blade is almost invariably a good thing. I
think the idiom came from "a sword cuts both ways", which is a much more
rational idiom.)

"Unreachable" indicators have been common in C programming for a very
long time, especially in code that needs to be efficient. And they are
used internally in C compilers more often - gcc and clang generate the
same internal representation for "__builtin_unreachable()" as they do
for code paths that result from undefined behaviour.

>
> However, it will end up defined as a statement whose purpose is to
> invoke undefined behavior. I.e. if [[unreachable]] is reached,
> the behavior is undefined, and that's how it works. The assumption
> that the program is free of undefined behavior means that no
> [[unreachable]] is reached.

Yes.

>
> Today, an abort() call serves as an expected unreachable point
> which has a defined behavior.

True - but an "abort()" call is not free. For small functions (such as
the "sign" function given by Keith a couple of posts up), it would
cripple the code efficiency.

For some code, it could be a good choice. For my own code, in most
cases where I use "__builtin_unreachable()", "abort" would almost
certainly a bad choice.

>
> If [[unreachable]] were defined as requiring a run-time diagnostic
> and termination if it is reached, rather than invoking UB, it would be
> more or less the same as abort(); little point in adding it.
>

Agreed - so it should /not/ be so defined. People who want "abort()"
know where to find it.

Note that since trying to execute "unreachable()" (as the C23 function
is called) is undefined behaviour, compilers can freely add debugging
and fault-finding options to give a run-time diagnostic if the code is
actually reached. But if the standard had defined the behaviour of
"unreachable()" to be somewhat like "abort()", compilers would not be
free to use it for efficient optimisation, or to aid static analysis.

Re: bart again (UCX64)

<4945f15a-22dd-431e-a732-81ed36615f27n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:15cd:b0:412:2107:7f1d with SMTP id d13-20020a05622a15cd00b0041221077f1dmr36341qty.7.1694161844581;
Fri, 08 Sep 2023 01:30:44 -0700 (PDT)
X-Received: by 2002:a63:b553:0:b0:573:ff6d:d462 with SMTP id
u19-20020a63b553000000b00573ff6dd462mr288809pgo.8.1694161844120; Fri, 08 Sep
2023 01:30:44 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 8 Sep 2023 01:30:43 -0700 (PDT)
In-Reply-To: <udeksu$3crce$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:3183:56e0:5605:146;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:3183:56e0:5605:146
References: <1262755563@f172.n1.z21.fsxnet> <A5pKM.1180698$TPw2.694138@fx17.iad>
<87h6o51rts.fsf@nosuchdomain.example.com> <GWwKM.320358$uLJb.75975@fx41.iad>
<87y1hhmehf.fsf@nosuchdomain.example.com> <20230907235623.619@kylheku.com> <udeksu$3crce$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4945f15a-22dd-431e-a732-81ed36615f27n@googlegroups.com>
Subject: Re: bart again (UCX64)
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Fri, 08 Sep 2023 08:30:44 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Malcolm McLean - Fri, 8 Sep 2023 08:30 UTC

On Friday, 8 September 2023 at 09:10:20 UTC+1, David Brown wrote:
>
> Note that since trying to execute "unreachable()" (as the C23 function
> is called) is undefined behaviour, compilers can freely add debugging
> and fault-finding options to give a run-time diagnostic if the code is
> actually reached. But if the standard had defined the behaviour of
> "unreachable()" to be somewhat like "abort()", compilers would not be
> free to use it for efficient optimisation, or to aid static analysis.
>
The difference is that the programmer might want to deliberately call
abort() as part of the expected runtime behaviour of the program. Whilst
unreachable() can only be called if he has made a programming error.
However he might want to fall back to defined behaviour in the case of
such an error.
However compilers can run unreachable code tests which would otherwise
be too expensive if they encounter an unreachable() statement. What
they can't do is use the unreachable() statement as a proof that the
code is in fact unreachable.

Re: bart again (UCX64)

<udepd1$3dal1$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: bart again (UCX64)
Date: Fri, 8 Sep 2023 11:26:57 +0200
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <udepd1$3dal1$2@dont-email.me>
References: <1262755563@f172.n1.z21.fsxnet>
<A5pKM.1180698$TPw2.694138@fx17.iad>
<87h6o51rts.fsf@nosuchdomain.example.com> <GWwKM.320358$uLJb.75975@fx41.iad>
<87y1hhmehf.fsf@nosuchdomain.example.com> <20230907235623.619@kylheku.com>
<udeksu$3crce$1@dont-email.me>
<4945f15a-22dd-431e-a732-81ed36615f27n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 8 Sep 2023 09:26:57 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="df8021775a6f8b7b93acd6c5303e221a";
logging-data="3582625"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/IypQCX6apEIWoK15wI9EzpFoBIW5VYnU="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:yfKeeJICYljuKSsWJq1MUQ5wfUo=
In-Reply-To: <4945f15a-22dd-431e-a732-81ed36615f27n@googlegroups.com>
Content-Language: en-GB
 by: David Brown - Fri, 8 Sep 2023 09:26 UTC

On 08/09/2023 10:30, Malcolm McLean wrote:
> On Friday, 8 September 2023 at 09:10:20 UTC+1, David Brown wrote:
>>
>> Note that since trying to execute "unreachable()" (as the C23 function
>> is called) is undefined behaviour, compilers can freely add debugging
>> and fault-finding options to give a run-time diagnostic if the code is
>> actually reached. But if the standard had defined the behaviour of
>> "unreachable()" to be somewhat like "abort()", compilers would not be
>> free to use it for efficient optimisation, or to aid static analysis.
>>
> The difference is that the programmer might want to deliberately call
> abort() as part of the expected runtime behaviour of the program. Whilst
> unreachable() can only be called if he has made a programming error.
> However he might want to fall back to defined behaviour in the case of
> such an error.

If a programmer wants such behaviour, then he or she should know how to
write it.

> However compilers can run unreachable code tests which would otherwise
> be too expensive if they encounter an unreachable() statement. What
> they can't do is use the unreachable() statement as a proof that the
> code is in fact unreachable.

Compilers can, and do, do exactly that. C is very much a "trust the
programmer" language, not a hand-holding language. If I write
"unreachable();", I expect my compiler to believe me and trust that the
code cannot ever be reached (or that I don't care what happens if it
/is/ reached). I don't want it to add extra code to check if the code
is reached, or to call abort() if it is reached. What I want is for the
compiler to use that extra information to make other code more
efficient, and to allow more compile-time warnings and static error
checking.

That's the deal with C - the compiler believes the programmer, and the
programmer is careful not to lie to the compiler. If you don't like
that, pick a different programming language.

So if you are not sure the code point is unreachable, don't "call"
unreachable(). It's very simple.

Re: bart again (UCX64)

<udeqdh$3dhqr$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: bart again (UCX64)
Date: Fri, 8 Sep 2023 10:44:17 +0100
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <udeqdh$3dhqr$1@dont-email.me>
References: <1262755563@f172.n1.z21.fsxnet>
<A5pKM.1180698$TPw2.694138@fx17.iad>
<87h6o51rts.fsf@nosuchdomain.example.com> <GWwKM.320358$uLJb.75975@fx41.iad>
<87y1hhmehf.fsf@nosuchdomain.example.com> <20230907235623.619@kylheku.com>
<udeksu$3crce$1@dont-email.me>
<4945f15a-22dd-431e-a732-81ed36615f27n@googlegroups.com>
<udepd1$3dal1$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 8 Sep 2023 09:44:17 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="a62b48b86c0a37f282ae77c8a0229d66";
logging-data="3589979"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18AUGMgsdtkt59a94dg73Ln6eCkSj+cmbo="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:Sw7ZO3efNeq12lbgXMv3t1S97zs=
In-Reply-To: <udepd1$3dal1$2@dont-email.me>
 by: Bart - Fri, 8 Sep 2023 09:44 UTC

On 08/09/2023 10:26, David Brown wrote:
> On 08/09/2023 10:30, Malcolm McLean wrote:
>> On Friday, 8 September 2023 at 09:10:20 UTC+1, David Brown wrote:
>>>
>>> Note that since trying to execute "unreachable()" (as the C23 function
>>> is called) is undefined behaviour, compilers can freely add debugging
>>> and fault-finding options to give a run-time diagnostic if the code is
>>> actually reached. But if the standard had defined the behaviour of
>>> "unreachable()" to be somewhat like "abort()", compilers would not be
>>> free to use it for efficient optimisation, or to aid static analysis.
>>>
>> The difference is that the programmer might want to deliberately call
>> abort() as part of the expected runtime behaviour of the program. Whilst
>> unreachable() can only be called if he has made a programming error.
>> However he might want to fall back to defined behaviour in the case of
>> such an error.
>
> If a programmer wants such behaviour, then he or she should know how to
> write it.
>
>> However compilers can run unreachable code tests which would otherwise
>> be too expensive if they encounter an unreachable() statement. What
>> they can't do is use the unreachable() statement as a proof that the
>> code is in fact unreachable.
>
> Compilers can, and do, do exactly that.  C is very much a "trust the
> programmer" language, not a hand-holding language.  If I write
> "unreachable();", I expect my compiler to believe me and trust that the
> code cannot ever be reached (or that I don't care what happens if it
> /is/ reached).  I don't want it to add extra code to check if the code
> is reached, or to call abort() if it is reached.  What I want is for the
> compiler to use that extra information to make other code more
> efficient, and to allow more compile-time warnings and static error
> checking.

It's funny that some people don't want the bother of writing 'return 0;'
in a path they know will never be reached, while others are prepared to
write 'unreachable();', which is both longer and uses shifted characters.

If the programmer is wrong however, 'unreachable()' won't stop garbage
(which can include a misleadingly correct result) from being returned.

> That's the deal with C - the compiler believes the programmer, and the
> programmer is careful not to lie to the compiler.  If you don't like
> that, pick a different programming language.

Which one that fixes that one detail and doesn't involve a total rewrite
of your software? And which doesn't introduce a hundred new problems
that are even more of a pain to deal with,

>
> So if you are not sure the code point is unreachable, don't "call"
> unreachable().  It's very simple.
>

Re: bart again (UCX64)

<543b9acc-de99-425c-bb1d-485e9f98889dn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:1914:b0:64a:24a4:3b9b with SMTP id er20-20020a056214191400b0064a24a43b9bmr31811qvb.13.1694166480384;
Fri, 08 Sep 2023 02:48:00 -0700 (PDT)
X-Received: by 2002:a17:902:e80f:b0:1c3:411c:9b7c with SMTP id
u15-20020a170902e80f00b001c3411c9b7cmr703384plg.13.1694166479849; Fri, 08 Sep
2023 02:47:59 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 8 Sep 2023 02:47:59 -0700 (PDT)
In-Reply-To: <udepd1$3dal1$2@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:3183:56e0:5605:146;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:3183:56e0:5605:146
References: <1262755563@f172.n1.z21.fsxnet> <A5pKM.1180698$TPw2.694138@fx17.iad>
<87h6o51rts.fsf@nosuchdomain.example.com> <GWwKM.320358$uLJb.75975@fx41.iad>
<87y1hhmehf.fsf@nosuchdomain.example.com> <20230907235623.619@kylheku.com>
<udeksu$3crce$1@dont-email.me> <4945f15a-22dd-431e-a732-81ed36615f27n@googlegroups.com>
<udepd1$3dal1$2@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <543b9acc-de99-425c-bb1d-485e9f98889dn@googlegroups.com>
Subject: Re: bart again (UCX64)
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Fri, 08 Sep 2023 09:48:00 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 4778
 by: Malcolm McLean - Fri, 8 Sep 2023 09:47 UTC

On Friday, 8 September 2023 at 10:27:12 UTC+1, David Brown wrote:
> On 08/09/2023 10:30, Malcolm McLean wrote:
> > On Friday, 8 September 2023 at 09:10:20 UTC+1, David Brown wrote:
> >>
> >> Note that since trying to execute "unreachable()" (as the C23 function
> >> is called) is undefined behaviour, compilers can freely add debugging
> >> and fault-finding options to give a run-time diagnostic if the code is
> >> actually reached. But if the standard had defined the behaviour of
> >> "unreachable()" to be somewhat like "abort()", compilers would not be
> >> free to use it for efficient optimisation, or to aid static analysis.
> >>
> > The difference is that the programmer might want to deliberately call
> > abort() as part of the expected runtime behaviour of the program. Whilst
> > unreachable() can only be called if he has made a programming error.
> > However he might want to fall back to defined behaviour in the case of
> > such an error.
> If a programmer wants such behaviour, then he or she should know how to
> write it.
> > However compilers can run unreachable code tests which would otherwise
> > be too expensive if they encounter an unreachable() statement. What
> > they can't do is use the unreachable() statement as a proof that the
> > code is in fact unreachable.
> Compilers can, and do, do exactly that. C is very much a "trust the
> programmer" language, not a hand-holding language. If I write
> "unreachable();", I expect my compiler to believe me and trust that the
> code cannot ever be reached (or that I don't care what happens if it
> /is/ reached). I don't want it to add extra code to check if the code
> is reached, or to call abort() if it is reached. What I want is for the
> compiler to use that extra information to make other code more
> efficient, and to allow more compile-time warnings and static error
> checking.
>
> That's the deal with C - the compiler believes the programmer, and the
> programmer is careful not to lie to the compiler. If you don't like
> that, pick a different programming language.
>
> So if you are not sure the code point is unreachable, don't "call"
> unreachable(). It's very simple.
>
This is a basic misunderstanding you have shown before.

In your world, you should never wear a seatbelt, because if you are at
risk of crashing into the car in front, you shouldn't be driving.
Of course that's nonsense. Experienced driver will occasionally have
moment of inattention. Very rarely, this will produce an accident,
and then the seatbelt is a life saver. Of course most seatbelts are
never used for their intended purpose. But it's still worth having.

Similarly, if you know that code cannot be reached, then unreachable()
can have undefined behaviour. But even experienced programmer make
mistakes. Less so maybe in the sort of programming you do. In
the sort of programming other people do, you often do have termination
conditions which depend on various mathematically proven properties
like convergence being correct. But of course threre could be a subtle
programming error which means that the mathematical property isn't
always met.
So a defined behaviour fallback is potentially useful. "This can't happen,
but if it does, give me this diagnostic".

Re: bart again (UCX64)

<udf0dl$3ehqn$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: bart again (UCX64)
Date: Fri, 8 Sep 2023 13:26:44 +0200
Organization: A noiseless patient Spider
Lines: 100
Message-ID: <udf0dl$3ehqn$1@dont-email.me>
References: <1262755563@f172.n1.z21.fsxnet>
<A5pKM.1180698$TPw2.694138@fx17.iad>
<87h6o51rts.fsf@nosuchdomain.example.com> <GWwKM.320358$uLJb.75975@fx41.iad>
<87y1hhmehf.fsf@nosuchdomain.example.com> <20230907235623.619@kylheku.com>
<udeksu$3crce$1@dont-email.me>
<4945f15a-22dd-431e-a732-81ed36615f27n@googlegroups.com>
<udepd1$3dal1$2@dont-email.me> <udeqdh$3dhqr$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 8 Sep 2023 11:26:45 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="df8021775a6f8b7b93acd6c5303e221a";
logging-data="3622743"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/a+VGyVtWN86qKNLqm6mbU9tyIQHccRUE="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:TMyOJIH1AVpmk2t/gbLZynoZLXQ=
Content-Language: en-GB
In-Reply-To: <udeqdh$3dhqr$1@dont-email.me>
 by: David Brown - Fri, 8 Sep 2023 11:26 UTC

On 08/09/2023 11:44, Bart wrote:
> On 08/09/2023 10:26, David Brown wrote:
>> On 08/09/2023 10:30, Malcolm McLean wrote:
>>> On Friday, 8 September 2023 at 09:10:20 UTC+1, David Brown wrote:
>>>>
>>>> Note that since trying to execute "unreachable()" (as the C23 function
>>>> is called) is undefined behaviour, compilers can freely add debugging
>>>> and fault-finding options to give a run-time diagnostic if the code is
>>>> actually reached. But if the standard had defined the behaviour of
>>>> "unreachable()" to be somewhat like "abort()", compilers would not be
>>>> free to use it for efficient optimisation, or to aid static analysis.
>>>>
>>> The difference is that the programmer might want to deliberately call
>>> abort() as part of the expected runtime behaviour of the program. Whilst
>>> unreachable() can only be called if he has made a programming error.
>>> However he might want to fall back to defined behaviour in the case of
>>> such an error.
>>
>> If a programmer wants such behaviour, then he or she should know how
>> to write it.
>>
>>> However compilers can run unreachable code tests which would otherwise
>>> be too expensive if they encounter an unreachable() statement. What
>>> they can't do is use the unreachable() statement as a proof that the
>>> code is in fact unreachable.
>>
>> Compilers can, and do, do exactly that.  C is very much a "trust the
>> programmer" language, not a hand-holding language.  If I write
>> "unreachable();", I expect my compiler to believe me and trust that
>> the code cannot ever be reached (or that I don't care what happens if
>> it /is/ reached).  I don't want it to add extra code to check if the
>> code is reached, or to call abort() if it is reached.  What I want is
>> for the compiler to use that extra information to make other code more
>> efficient, and to allow more compile-time warnings and static error
>> checking.
>
>
> It's funny that some people don't want the bother of writing 'return 0;'
> in a path they know will never be reached, while others are prepared to
> write 'unreachable();', which is both longer and uses shifted characters.
>

Some of us get paid to write good quality, readable and maintainable
software. I suppose there are other programmers who get paid per letter
they type, or are charged per byte of disk space they use, for whom the
number of keystrokes is a relevant metric.

I don't want to write "return 0;" if that line will never be executed,
because it would be misleading and untestable. I /do/ want to write
"unreachable();" because it is clear and precise, giving important
information to both the compiler and readers.

> If the programmer is wrong however, 'unreachable()' won't stop garbage
> (which can include a misleadingly correct result) from being returned.

That is true. But if the programmer is wrong and writes "return 0;" in
the wrong place, things could go equally badly. When programmers write
the wrong thing, bad things may happen - that's inevitable in
programming. One way to minimise the risk of that is by writing code
that makes sense - say what the code does, such as writing
"unreachable();" when you know that line cannot be reached, rather than
writing nonsense such as "return 0;" when the code cannot return from there.

>
>
>> That's the deal with C - the compiler believes the programmer, and the
>> programmer is careful not to lie to the compiler.  If you don't like
>> that, pick a different programming language.
>
> Which one that fixes that one detail and doesn't involve a total rewrite
> of your software?

Which "one detail" are you talking about? Malcolm was complaining that
compilers might believe a programmer that wrote "unreachable();". I
don't consider that to be something that needs fixing, and I don't
consider the general point of compilers trusting the programmer as
either something to fix, or a single detail.

> And which doesn't introduce a hundred new problems
> that are even more of a pain to deal with,

That's not my problem. I don't know of any programming language where
the tools do not trust what the programmer writes or where the
programmer can lie or mislead the compiler with impunity. But if
Malcolm wants to be able to do that, it is up to him to try to find a
language that suits his needs better than C. Maybe something with a
restricted virtual machine would suit him.

I make a point of trying to pick the right language for any given task -
whether it be C (and if so, which standards version, which extensions,
which restrictions, which coding standard, etc.), C++, Python, or
something else. There are often many factors to consider.

>
>>
>> So if you are not sure the code point is unreachable, don't "call"
>> unreachable().  It's very simple.
>>
>

Re: bart again (UCX64)

<udf9jn$3fta8$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: bart again (UCX64)
Date: Fri, 8 Sep 2023 16:03:34 +0200
Organization: A noiseless patient Spider
Lines: 154
Message-ID: <udf9jn$3fta8$1@dont-email.me>
References: <1262755563@f172.n1.z21.fsxnet>
<A5pKM.1180698$TPw2.694138@fx17.iad>
<87h6o51rts.fsf@nosuchdomain.example.com> <GWwKM.320358$uLJb.75975@fx41.iad>
<87y1hhmehf.fsf@nosuchdomain.example.com> <20230907235623.619@kylheku.com>
<udeksu$3crce$1@dont-email.me>
<4945f15a-22dd-431e-a732-81ed36615f27n@googlegroups.com>
<udepd1$3dal1$2@dont-email.me>
<543b9acc-de99-425c-bb1d-485e9f98889dn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 8 Sep 2023 14:03:35 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="df8021775a6f8b7b93acd6c5303e221a";
logging-data="3667272"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+qrbPZlHeuEhM0wlt0B96rKtyqsOk/sB0="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:fHFM5UESpbg5XmXT7NJ3uh0rPYA=
In-Reply-To: <543b9acc-de99-425c-bb1d-485e9f98889dn@googlegroups.com>
Content-Language: en-GB
 by: David Brown - Fri, 8 Sep 2023 14:03 UTC

On 08/09/2023 11:47, Malcolm McLean wrote:
> On Friday, 8 September 2023 at 10:27:12 UTC+1, David Brown wrote:
>> On 08/09/2023 10:30, Malcolm McLean wrote:
>>> On Friday, 8 September 2023 at 09:10:20 UTC+1, David Brown wrote:
>>>>
>>>> Note that since trying to execute "unreachable()" (as the C23 function
>>>> is called) is undefined behaviour, compilers can freely add debugging
>>>> and fault-finding options to give a run-time diagnostic if the code is
>>>> actually reached. But if the standard had defined the behaviour of
>>>> "unreachable()" to be somewhat like "abort()", compilers would not be
>>>> free to use it for efficient optimisation, or to aid static analysis.
>>>>
>>> The difference is that the programmer might want to deliberately call
>>> abort() as part of the expected runtime behaviour of the program. Whilst
>>> unreachable() can only be called if he has made a programming error.
>>> However he might want to fall back to defined behaviour in the case of
>>> such an error.
>> If a programmer wants such behaviour, then he or she should know how to
>> write it.
>>> However compilers can run unreachable code tests which would otherwise
>>> be too expensive if they encounter an unreachable() statement. What
>>> they can't do is use the unreachable() statement as a proof that the
>>> code is in fact unreachable.
>> Compilers can, and do, do exactly that. C is very much a "trust the
>> programmer" language, not a hand-holding language. If I write
>> "unreachable();", I expect my compiler to believe me and trust that the
>> code cannot ever be reached (or that I don't care what happens if it
>> /is/ reached). I don't want it to add extra code to check if the code
>> is reached, or to call abort() if it is reached. What I want is for the
>> compiler to use that extra information to make other code more
>> efficient, and to allow more compile-time warnings and static error
>> checking.
>>
>> That's the deal with C - the compiler believes the programmer, and the
>> programmer is careful not to lie to the compiler. If you don't like
>> that, pick a different programming language.
>>
>> So if you are not sure the code point is unreachable, don't "call"
>> unreachable(). It's very simple.
>>
> This is a basic misunderstanding you have shown before.

No, I am not misunderstanding anything - but I think /you/ are greatly
misunderstanding /me/.

>
> In your world, you should never wear a seatbelt, because if you are at
> risk of crashing into the car in front, you shouldn't be driving.

Not at all - that is not even remotely equivalent. I am surprised that
someone as experience in programming as yourself does not see it
immediately.

The risks when driving are unknowns - other people on the road, icy
patches, kids jumping out in front of the car, etc. Some things you
have partial control over, such as how well you have learned to drive,
others you don't - such as an unexpected sneeze. These are all inputs -
and your code should always check and sanitize input data from unknown
sources.

Compile-time information is about the car and/or driver, not the trip.
You check the seat is in the right position once, before starting, not
every time you want to press a pedal. You trust that the experts do
their job - you don't open up the wheel mountings to see if the brakes
are in order, but trust the mechanic at the workshop. When you turn the
steering wheel, the car's wheels turn - because the car "trusts" that
the driver knows what he or she is doing.

And more relevantly, when writing software, you check the code at many
stages - you check it when writing it, you test it at run-time, you have
other people check it in code reviews, you have your static error
checking software check what it can. You don't whip together a bunch of
code and deploy it on the basis of "it compiles, so it must be right -
any serious issue would have given an error on compilation, not just a
warning." /That/ would be more akin to driving without a seat belt.

So - back to reality and programming. I write "unreachable()" for parts
of the code that I know can never be reached, because that is useful
information to readers and the compiler. I expect the compiler to trust
me, and to make use of that information to optimise the code. That's
the compiler's job - I write in clear, high-level C code, and it turns
that into efficient object code.

If I see someone has written code such as :

abort(); // Can never reach this

I know that something in the development process is broken or
untrustworthy. Perhaps the programmer can't trust the compiler - there
are occasions when people have no choice but to use poor quality tools,
and even the best tools are not bug-free. Perhaps the programmer is
inexperienced, and thinks this is a good idea. Perhaps the warnings
used in the compiler complain if there is nothing there (such as if you
use Bart's compiler in the examples discussed). Perhaps the project
manager is inexperienced, and thinks this is a case of being "doubly
safe". Certainly something is wrong.

> Of course that's nonsense.

Yes, I agree - your analogy was utter nonsense.

>
> Similarly, if you know that code cannot be reached, then unreachable()
> can have undefined behaviour.

No.

We are talking here about run-time undefined behaviour. Since the code
line will never be reached when running the program, there cannot be
undefined behaviour from it (or defined behaviour, for that matter -
there is /no/ behaviour as it does not run).

> But even experienced programmer make
> mistakes. Less so maybe in the sort of programming you do. In
> the sort of programming other people do, you often do have termination
> conditions which depend on various mathematically proven properties
> like convergence being correct. But of course threre could be a subtle
> programming error which means that the mathematical property isn't
> always met.

If there is a possibility of the code reaching that point,
"unreachable()" would not be appropriate.

It's a bit like noting that if you don't want to write some output to
the terminal, writing "printf" is not appropriate.

What is so difficult about writing what you mean when programming?

Sure, programmers make mistakes. That's why you have code reviews, and
testing. That's why you use a debugger, and sanitizers, and other
tools. That's why it is important to write code that you mean, and not
nonsense that you don't mean. And you don't write code that is
untestable such as lines that cannot be reached, or code that makes no
sense to a reviewer claiming to do something in impossible situations.

>
> So a defined behaviour fallback is potentially useful. "This can't happen,
> but if it does, give me this diagnostic".

Where did you learn about logic? From watching Monty Python?

Things that can't happen, can't happen. If the thing /might/ happen,
then it /can/ happen.

Do you think I write my code by guesswork? Do you think I say to
myself, "I guess this is unlikely, and I don't want to consider it -
we'll pretend it it's impossible and tell the compiler its unreachable.
I'm sure no one will notice" ?

Re: bart again (UCX64)

<7kGKM.80955$Wk53.72758@fx01.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx01.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: bart again (UCX64)
Newsgroups: comp.lang.c
References: <1262755563@f172.n1.z21.fsxnet> <A5pKM.1180698$TPw2.694138@fx17.iad> <87h6o51rts.fsf@nosuchdomain.example.com> <GWwKM.320358$uLJb.75975@fx41.iad> <87y1hhmehf.fsf@nosuchdomain.example.com> <20230907235623.619@kylheku.com> <udeksu$3crce$1@dont-email.me> <4945f15a-22dd-431e-a732-81ed36615f27n@googlegroups.com>
Lines: 14
Message-ID: <7kGKM.80955$Wk53.72758@fx01.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Fri, 08 Sep 2023 14:36:51 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Fri, 08 Sep 2023 14:36:51 GMT
X-Received-Bytes: 1630
 by: Scott Lurndal - Fri, 8 Sep 2023 14:36 UTC

Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>On Friday, 8 September 2023 at 09:10:20 UTC+1, David Brown wrote:
>>
>> Note that since trying to execute "unreachable()" (as the C23 function
>> is called) is undefined behaviour, compilers can freely add debugging
>> and fault-finding options to give a run-time diagnostic if the code is
>> actually reached. But if the standard had defined the behaviour of
>> "unreachable()" to be somewhat like "abort()", compilers would not be
>> free to use it for efficient optimisation, or to aid static analysis.
>>
>The difference is that the programmer might want to deliberately call
>abort() as part of the expected runtime behaviour of the program.

Not in any company I've worked with. abort() is extremely user-unfriendly.

Re: bart again (UCX64)

<7cf7b6bd-39d9-4e22-baee-e128cfb2f214n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:37a4:b0:76f:c32:705f with SMTP id pi36-20020a05620a37a400b0076f0c32705fmr87115qkn.2.1694214388380;
Fri, 08 Sep 2023 16:06:28 -0700 (PDT)
X-Received: by 2002:a17:90a:7f89:b0:268:3469:d86e with SMTP id
m9-20020a17090a7f8900b002683469d86emr964561pjl.1.1694214387902; Fri, 08 Sep
2023 16:06:27 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 8 Sep 2023 16:06:27 -0700 (PDT)
In-Reply-To: <udf9jn$3fta8$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:3183:56e0:5605:146;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:3183:56e0:5605:146
References: <1262755563@f172.n1.z21.fsxnet> <A5pKM.1180698$TPw2.694138@fx17.iad>
<87h6o51rts.fsf@nosuchdomain.example.com> <GWwKM.320358$uLJb.75975@fx41.iad>
<87y1hhmehf.fsf@nosuchdomain.example.com> <20230907235623.619@kylheku.com>
<udeksu$3crce$1@dont-email.me> <4945f15a-22dd-431e-a732-81ed36615f27n@googlegroups.com>
<udepd1$3dal1$2@dont-email.me> <543b9acc-de99-425c-bb1d-485e9f98889dn@googlegroups.com>
<udf9jn$3fta8$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7cf7b6bd-39d9-4e22-baee-e128cfb2f214n@googlegroups.com>
Subject: Re: bart again (UCX64)
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Fri, 08 Sep 2023 23:06:28 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2879
 by: Malcolm McLean - Fri, 8 Sep 2023 23:06 UTC

On Friday, 8 September 2023 at 15:03:51 UTC+1, David Brown wrote:
> On 08/09/2023 11:47, Malcolm McLean wrote:
>
> > So a defined behaviour fallback is potentially useful. "This can't happen,
> > but if it does, give me this diagnostic".
> Where did you learn about logic? From watching Monty Python?
>
> Things that can't happen, can't happen. If the thing /might/ happen,
> then it /can/ happen.
>
> Do you think I write my code by guesswork? Do you think I say to
> myself, "I guess this is unlikely, and I don't want to consider it -
> we'll pretend it it's impossible and tell the compiler its unreachable.
> I'm sure no one will notice" ?
>
OK so

int sign(double x)
{ if (x < 0) return -1;
if (x == 0) retun 0;
if (x > 0) return 1;
/* unreachable */
}

Yes?
No. In David Brown world, no-one would ever make that mistake. In reality,
it's the sort of thing that is quite likely to slip through. In fact sign() needs
to return a double to handle the corner case properly.

It's NaN of course. The sign of NaN is NaN.
Or you could say that NaN isn't in the domain of the function and either catch
it, or just ignore it and accept any garbage - the real bug will be upstream.
Or you could say that the code is unreachable because we always filter
out NaN. But how would you prove that?

Re: bart again (UCX64)

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

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: bart again (UCX64)
Date: Sat, 09 Sep 2023 01:52:15 +0100
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <874jk4mam8.fsf@bsb.me.uk>
References: <1262755563@f172.n1.z21.fsxnet>
<A5pKM.1180698$TPw2.694138@fx17.iad>
<87h6o51rts.fsf@nosuchdomain.example.com>
<GWwKM.320358$uLJb.75975@fx41.iad>
<87y1hhmehf.fsf@nosuchdomain.example.com>
<20230907235623.619@kylheku.com> <udeksu$3crce$1@dont-email.me>
<4945f15a-22dd-431e-a732-81ed36615f27n@googlegroups.com>
<udepd1$3dal1$2@dont-email.me>
<543b9acc-de99-425c-bb1d-485e9f98889dn@googlegroups.com>
<udf9jn$3fta8$1@dont-email.me>
<7cf7b6bd-39d9-4e22-baee-e128cfb2f214n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="af15565c84ea4ea7db7cc714af21fb35";
logging-data="3962681"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Q0ZUjFMWgbpxUXgg7ITMpD2UhV2zIHvM="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:VQCodFxhaJLSB1cJvwPIZIMIy90=
sha1:NRXtNNeDDod8XRWLCIOugwkOvRU=
X-BSB-Auth: 1.6b711c44879f20e8904a.20230909015215BST.874jk4mam8.fsf@bsb.me.uk
 by: Ben Bacarisse - Sat, 9 Sep 2023 00:52 UTC

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

> int sign(double x)
> {
> if (x < 0) return -1;
> if (x == 0) retun 0;
> if (x > 0) return 1;
> /* unreachable */
> }

Just for information...

> In fact sign() needs to return a double to handle the corner case properly.
>
> It's NaN of course. The sign of NaN is NaN.

In IEEE floating point (almost universal these days) NaNs (and
infinities) are signed, and the sign often carries useful information.
You can't just state that "the sign of NaN is NaN" as if it's a plain
fact. One might want, for example, something more like:

return x == 0 ? 0 : 1 - 2*signbit(x);

The information alluded to above being that some readers may not know
that C has a signbit macro.

--
Ben.

Re: bart again (UCX64)

<14ea840a-b27e-49c3-99b0-edebbb020662n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:45a5:b0:76f:133f:83bd with SMTP id bp37-20020a05620a45a500b0076f133f83bdmr108385qkb.14.1694222219890;
Fri, 08 Sep 2023 18:16:59 -0700 (PDT)
X-Received: by 2002:a63:3f07:0:b0:563:84fc:f4dd with SMTP id
m7-20020a633f07000000b0056384fcf4ddmr791744pga.6.1694222219396; Fri, 08 Sep
2023 18:16:59 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 8 Sep 2023 18:16:58 -0700 (PDT)
In-Reply-To: <874jk4mam8.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:3183:56e0:5605:146;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:3183:56e0:5605:146
References: <1262755563@f172.n1.z21.fsxnet> <A5pKM.1180698$TPw2.694138@fx17.iad>
<87h6o51rts.fsf@nosuchdomain.example.com> <GWwKM.320358$uLJb.75975@fx41.iad>
<87y1hhmehf.fsf@nosuchdomain.example.com> <20230907235623.619@kylheku.com>
<udeksu$3crce$1@dont-email.me> <4945f15a-22dd-431e-a732-81ed36615f27n@googlegroups.com>
<udepd1$3dal1$2@dont-email.me> <543b9acc-de99-425c-bb1d-485e9f98889dn@googlegroups.com>
<udf9jn$3fta8$1@dont-email.me> <7cf7b6bd-39d9-4e22-baee-e128cfb2f214n@googlegroups.com>
<874jk4mam8.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <14ea840a-b27e-49c3-99b0-edebbb020662n@googlegroups.com>
Subject: Re: bart again (UCX64)
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Sat, 09 Sep 2023 01:16:59 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2660
 by: Malcolm McLean - Sat, 9 Sep 2023 01:16 UTC

On Saturday, 9 September 2023 at 01:52:30 UTC+1, Ben Bacarisse wrote:
> Malcolm McLean <malcolm.ar...@gmail.com> writes:
>
> > int sign(double x)
> > {
> > if (x < 0) return -1;
> > if (x == 0) retun 0;
> > if (x > 0) return 1;
> > /* unreachable */
> > }
> Just for information...
> > In fact sign() needs to return a double to handle the corner case properly.
> >
> > It's NaN of course. The sign of NaN is NaN.
> In IEEE floating point (almost universal these days) NaNs (and
> infinities) are signed, and the sign often carries useful information.
> You can't just state that "the sign of NaN is NaN" as if it's a plain
> fact. One might want, for example, something more like:
>
> return x == 0 ? 0 : 1 - 2*signbit(x);
>
> The information alluded to above being that some readers may not know
> that C has a signbit macro.
>
IEEE also allows for signed zero. But the sign of zero is zero. Certainly for
positive zero. I suppose you might argue that for the rare negative zeroes
you should return -1.

Re: bart again (UCX64)

<20230908184633.897@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: bart again (UCX64)
Date: Sat, 9 Sep 2023 01:48:45 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <20230908184633.897@kylheku.com>
References: <1262755563@f172.n1.z21.fsxnet>
<A5pKM.1180698$TPw2.694138@fx17.iad>
<87h6o51rts.fsf@nosuchdomain.example.com>
<GWwKM.320358$uLJb.75975@fx41.iad>
<87y1hhmehf.fsf@nosuchdomain.example.com> <20230907235623.619@kylheku.com>
<udeksu$3crce$1@dont-email.me>
<4945f15a-22dd-431e-a732-81ed36615f27n@googlegroups.com>
<udepd1$3dal1$2@dont-email.me> <udeqdh$3dhqr$1@dont-email.me>
Injection-Date: Sat, 9 Sep 2023 01:48:45 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cbf43b42d7a4bc81e1a1f81e08c9fb9f";
logging-data="3974770"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/y/OPnCcLAek8L3xq6xvzjm32qPpA7CLY="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:y+zOUHl9z4fwh6LjhS1Wjblfjj4=
 by: Kaz Kylheku - Sat, 9 Sep 2023 01:48 UTC

On 2023-09-08, Bart <bc@freeuk.com> wrote:
> It's funny that some people don't want the bother of writing 'return 0;'
> in a path they know will never be reached, while others are prepared to
> write 'unreachable();', which is both longer and uses shifted characters.

What is worse, the original program with a missing "return 0;" might
well be correct. If the caller doesn't extract the return value,
everything is copacetic.

Whereas unreachable() is a gizmo whose only meaning is that it invokes
undefined behavior if executed!

It's like you have a pepper shaker on your programing table labeled
"UB", and you sprinkle that on your program.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: bart again (UCX64)

<20230908184909.736@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: bart again (UCX64)
Date: Sat, 9 Sep 2023 01:50:43 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <20230908184909.736@kylheku.com>
References: <1262755563@f172.n1.z21.fsxnet>
<A5pKM.1180698$TPw2.694138@fx17.iad>
<87h6o51rts.fsf@nosuchdomain.example.com>
<GWwKM.320358$uLJb.75975@fx41.iad>
<87y1hhmehf.fsf@nosuchdomain.example.com> <20230907235623.619@kylheku.com>
<udeksu$3crce$1@dont-email.me>
<4945f15a-22dd-431e-a732-81ed36615f27n@googlegroups.com>
<7kGKM.80955$Wk53.72758@fx01.iad>
Injection-Date: Sat, 9 Sep 2023 01:50:43 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cbf43b42d7a4bc81e1a1f81e08c9fb9f";
logging-data="3974770"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/QWCg06w77kXlw8vur2r4iOS6bmupZLmY="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:HipeBQi6tJpqEa5ImOdKYp2rFY4=
 by: Kaz Kylheku - Sat, 9 Sep 2023 01:50 UTC

On 2023-09-08, Scott Lurndal <scott@slp53.sl.home> wrote:
> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>>On Friday, 8 September 2023 at 09:10:20 UTC+1, David Brown wrote:
>>>
>>> Note that since trying to execute "unreachable()" (as the C23 function
>>> is called) is undefined behaviour, compilers can freely add debugging
>>> and fault-finding options to give a run-time diagnostic if the code is
>>> actually reached. But if the standard had defined the behaviour of
>>> "unreachable()" to be somewhat like "abort()", compilers would not be
>>> free to use it for efficient optimisation, or to aid static analysis.
>>>
>>The difference is that the programmer might want to deliberately call
>>abort() as part of the expected runtime behaviour of the program.
>
> Not in any company I've worked with. abort() is extremely user-unfriendly.

It's better than exit. More than once I had to fix a well-meaning
exit(0) or exit(1) in error handling code to abort.

For instance if you have the program under the debugger, abort will
stop and you ahve a call stack.

To get that from exit, you have to put a breakpoint on exit.

abort() can leave core dumps.

If all you do is call abort, it's user unfriendly because there is
no diagnostic. However, the astute Unix graybeard will notice that
the program died due to signal 6. :)

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: bart again (UCX64)

<20230908185106.539@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: bart again (UCX64)
Date: Sat, 9 Sep 2023 01:57:47 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 49
Message-ID: <20230908185106.539@kylheku.com>
References: <1262755563@f172.n1.z21.fsxnet>
<A5pKM.1180698$TPw2.694138@fx17.iad>
<87h6o51rts.fsf@nosuchdomain.example.com>
<GWwKM.320358$uLJb.75975@fx41.iad>
<87y1hhmehf.fsf@nosuchdomain.example.com> <20230907235623.619@kylheku.com>
<udeksu$3crce$1@dont-email.me>
<4945f15a-22dd-431e-a732-81ed36615f27n@googlegroups.com>
<udepd1$3dal1$2@dont-email.me> <udeqdh$3dhqr$1@dont-email.me>
<udf0dl$3ehqn$1@dont-email.me>
Injection-Date: Sat, 9 Sep 2023 01:57:47 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cbf43b42d7a4bc81e1a1f81e08c9fb9f";
logging-data="3974770"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/5A6hrC7wzhMLwbVL91nQHugwXlH0pOkI="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:hxnOUFKORDQd7HIaZA9YR2F7VKw=
 by: Kaz Kylheku - Sat, 9 Sep 2023 01:57 UTC

On 2023-09-08, David Brown <david.brown@hesbynett.no> wrote:
> I don't want to write "return 0;" if that line will never be executed,
> because it would be misleading and untestable.

OK; that's a situation in which you consciously don't want it;
you're not omitting it because you got distracted.

> I /do/ want to write
> "unreachable();" because it is clear and precise, giving important
> information to both the compiler and readers.

But then you have to be sure that this logical fact is true;
since it is an iron-clad assertion, the justification behind it
(which the compiler doesn't see nor care about) has to be iron
clad.

There is a risk in it because it's possible that if you neither
add "return 0" nor "unreachable()" that the situation might not
be erroneous at all if that end is reached.

Whereas with unreachable() that becomes UB.
>
>> If the programmer is wrong however, 'unreachable()' won't stop garbage
>> (which can include a misleadingly correct result) from being returned.
>
> That is true. But if the programmer is wrong and writes "return 0;" in
> the wrong place, things could go equally badly.

Not there though; somewhere farther down the road where the can has
been kicked. But yes.

> When programmers write
> the wrong thing, bad things may happen - that's inevitable in
> programming. One way to minimise the risk of that is by writing code
> that makes sense - say what the code does, such as writing
> "unreachable();" when you know that line cannot be reached, rather than
> writing nonsense such as "return 0;" when the code cannot return from there.

Or abort() when that makes sense; like that it would be bad for that
code to be reached, and we don't think it is, but we are not so
committed to that proposition that we're willing to bet on it with
undefined behavior. And we don't mind the extra instructions for that in
that situation.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: bart again (UCX64)

<20230908185812.914@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: bart again (UCX64)
Date: Sat, 9 Sep 2023 02:17:41 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 117
Message-ID: <20230908185812.914@kylheku.com>
References: <1262755563@f172.n1.z21.fsxnet>
<A5pKM.1180698$TPw2.694138@fx17.iad>
<87h6o51rts.fsf@nosuchdomain.example.com>
<GWwKM.320358$uLJb.75975@fx41.iad>
<87y1hhmehf.fsf@nosuchdomain.example.com> <20230907235623.619@kylheku.com>
<udeksu$3crce$1@dont-email.me>
<4945f15a-22dd-431e-a732-81ed36615f27n@googlegroups.com>
<udepd1$3dal1$2@dont-email.me>
Injection-Date: Sat, 9 Sep 2023 02:17:41 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cbf43b42d7a4bc81e1a1f81e08c9fb9f";
logging-data="4107445"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX181U/CBfQteM5uDhy1xjYz3W9RBl/itfK8="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:Kc73Jw2wbK1QKU4KPeAnD8Pqfn0=
 by: Kaz Kylheku - Sat, 9 Sep 2023 02:17 UTC

On 2023-09-08, David Brown <david.brown@hesbynett.no> wrote:
> So if you are not sure the code point is unreachable, don't "call"
> unreachable(). It's very simple.

Here is a bit of evening entertainment.

In a Lisp compiler I developed I was suprised to see that it optimized
away the return sequence from a function due to that being unreachable
(not by being declared that way, just deduced trhough control flow
analysis).

Watch what happens to at optimization levels 0, 3 and 5 to the
expression (while t (put-line "hello")), an infinite loop:

I was surprised because I was not "after" that at all; the optimizations were
not developed with that specific situation in mind.

It's a like when people write chess programs which then surprise them
by playing betetr than their makers.

Baseline code geneartion at level zero:

1> (let ((*opt-level* 0)) (disassemble (compile-toplevel '(while t (put-line "hello")))))
data:
0: t
1: "hello"
syms:
0: put-line
code:
0: 4C00000B block t2 nil 11
1: 00020000
2: 04020000 frame 2 0
3: 38000008 if d0 8
4: 00000400
5: 20010005 gcall t5 0 d1
6: 04010000
7: 34000003 jmp 3
8: 10000000 end nil
9: 2C020000 movsr t2 nil
10: 10000002 end t2
11: 10000002 end t2
instruction count:
9
#<sys:vm-desc: 9009a60>

At level 3, the block and frame are removed. However, "if d0 5" is being
stupidly executed. This means branch off to the instruction at offset 5 if the
condition is NOT true, otherwise proceed. d0 refers to a static data register,
which holds the t symbol; the condition is always true.

2> (let ((*opt-level* 3)) (disassemble (compile-toplevel '(while t (put-line "hello")))))
data:
0: t
1: "hello"
syms:
0: put-line
code:
0: 38000005 if d0 5
1: 00000400
2: 20010005 gcall t5 0 d1
3: 04010000
4: 34000000 jmp 0
5: 10000000 end nil
instruction count:
4
#<sys:vm-desc: 90cd530>

At level 5, things get more clever. The pointless if instruction is removed.

The "5 ... end nil" instruction was only reachable through that instruction
taking the branch, and so that instruction is gone:

3> (let ((*opt-level* 5)) (disassemble (compile-toplevel '(while t (put-line "hello")))))
data:
0: "hello"
syms:
0: put-line
code:
0: 20010005 gcall t5 0 d0
1: 04000000
2: 34000000 jmp 0
instruction count:
2
#<sys:vm-desc: 927f610>

So now the function doesn't include a wasteful end instruction.
That stood out to my eyes right away because right until that point I was so
used to seeing those terminating "end" instructions.

In C, a compiler could do something similar: when the end of the function is
not reachable, it could omit emitting any register restoring code and ret
instruction, making the function smaller.

Now if you lie to the compiler that the end is unreachable, even though it is,
it could do the optimization code anyway, and leave the branch in place. Or
remove the branch also, and adjust the jmp so that the loop becomes infinite.

For instance suppose the instruction tested some register t4, which gets
loaded from some global variable that could be changing. that "if t4 5",
in the false case, jumps to code that we have declard unreachable.
There is no point in that, so the instruction gets erased.

Since the instruction gets erased, the instruction which calculated t4
now by accessing the global variable now a dead t4 register.
So that instruction gets removed. The backwards jmp in the loop
now goes to whatever instruction follows: the loop has become infinite;
repeating without testing that global variable.

Wrong facts that you declare trigger a cascade of deductions that are
increasingly removed from the circumstances of that fact.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: bart again (UCX64)

<Cl0LM.1449506$GMN3.722040@fx16.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.1d4.us!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx16.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: bart again (UCX64)
Newsgroups: comp.lang.c
References: <1262755563@f172.n1.z21.fsxnet> <A5pKM.1180698$TPw2.694138@fx17.iad> <87h6o51rts.fsf@nosuchdomain.example.com> <GWwKM.320358$uLJb.75975@fx41.iad> <87y1hhmehf.fsf@nosuchdomain.example.com> <20230907235623.619@kylheku.com> <udeksu$3crce$1@dont-email.me> <4945f15a-22dd-431e-a732-81ed36615f27n@googlegroups.com> <7kGKM.80955$Wk53.72758@fx01.iad> <20230908184909.736@kylheku.com>
Lines: 26
Message-ID: <Cl0LM.1449506$GMN3.722040@fx16.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Sat, 09 Sep 2023 15:40:18 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Sat, 09 Sep 2023 15:40:18 GMT
X-Received-Bytes: 2254
 by: Scott Lurndal - Sat, 9 Sep 2023 15:40 UTC

Kaz Kylheku <864-117-4973@kylheku.com> writes:
>On 2023-09-08, Scott Lurndal <scott@slp53.sl.home> wrote:
>> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>>>On Friday, 8 September 2023 at 09:10:20 UTC+1, David Brown wrote:
>>>>
>>>> Note that since trying to execute "unreachable()" (as the C23 function
>>>> is called) is undefined behaviour, compilers can freely add debugging
>>>> and fault-finding options to give a run-time diagnostic if the code is
>>>> actually reached. But if the standard had defined the behaviour of
>>>> "unreachable()" to be somewhat like "abort()", compilers would not be
>>>> free to use it for efficient optimisation, or to aid static analysis.
>>>>
>>>The difference is that the programmer might want to deliberately call
>>>abort() as part of the expected runtime behaviour of the program.
>>
>> Not in any company I've worked with. abort() is extremely user-unfriendly.
>
>It's better than exit. More than once I had to fix a well-meaning
>exit(0) or exit(1) in error handling code to abort.

I do not disagree with that statement; I did not intend to imply
that simply exit was a proper error handling mechanism.

There are a number of ways to produce useful information in such
a situation if it cannot be recovered from (which should be the
first choice, when possible).

Re: bart again (UCX64)

<udi6v0$52sl$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: bart again (UCX64)
Date: Sat, 9 Sep 2023 18:36:47 +0200
Organization: A noiseless patient Spider
Lines: 92
Message-ID: <udi6v0$52sl$1@dont-email.me>
References: <1262755563@f172.n1.z21.fsxnet>
<A5pKM.1180698$TPw2.694138@fx17.iad>
<87h6o51rts.fsf@nosuchdomain.example.com> <GWwKM.320358$uLJb.75975@fx41.iad>
<87y1hhmehf.fsf@nosuchdomain.example.com> <20230907235623.619@kylheku.com>
<udeksu$3crce$1@dont-email.me>
<4945f15a-22dd-431e-a732-81ed36615f27n@googlegroups.com>
<udepd1$3dal1$2@dont-email.me> <udeqdh$3dhqr$1@dont-email.me>
<udf0dl$3ehqn$1@dont-email.me> <20230908185106.539@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 9 Sep 2023 16:36:48 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="010d235d15fa84e76a575c550a4815f1";
logging-data="166805"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18gNikWZO8DuWYNtPL3js5B6mubh2auImU="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Cancel-Lock: sha1:dgSLOCIwKo476zhFIGKp62CWFo0=
Content-Language: en-GB
In-Reply-To: <20230908185106.539@kylheku.com>
 by: David Brown - Sat, 9 Sep 2023 16:36 UTC

On 09/09/2023 03:57, Kaz Kylheku wrote:
> On 2023-09-08, David Brown <david.brown@hesbynett.no> wrote:
>> I don't want to write "return 0;" if that line will never be executed,
>> because it would be misleading and untestable.
>
> OK; that's a situation in which you consciously don't want it;
> you're not omitting it because you got distracted.

Correct.

A warning (such as gcc has) based on reachability analysis in a compiler
should be able to warn about real missing returns without false
positives about clearly unreachable situations, so there is no need to
add such unhelpful returns. In some situations, the programmer knows
more than the compiler, and the compiler can't prove that the final
close braces is unreachable - that's when it is helpful to write
"unreachable();" explicitly.

>
>> I /do/ want to write
>> "unreachable();" because it is clear and precise, giving important
>> information to both the compiler and readers.
>
> But then you have to be sure that this logical fact is true;
> since it is an iron-clad assertion, the justification behind it
> (which the compiler doesn't see nor care about) has to be iron
> clad.

Yes.

But if I write "p++;", I also have to be absolutely sure that this is
the correct action at the time. That's how programming works - I really
do not see why anyone would think "unreachable();" is so special.

>
> There is a risk in it because it's possible that if you neither
> add "return 0" nor "unreachable()" that the situation might not
> be erroneous at all if that end is reached.
>

"Possibly not erroneous" implies "possibly erroneous", which - by
definition - means "undefined behaviour", because you can't be sure
about what will happen. So you are worried about adding explicit
undefined behaviour in a situation where you currently already have
undefined behaviour?

Do you understand why I don't see writing "unreachable();" as
particularly dangerous, compared to anything else in the code?

> Whereas with unreachable() that becomes UB.
>>
>>> If the programmer is wrong however, 'unreachable()' won't stop garbage
>>> (which can include a misleadingly correct result) from being returned.
>>
>> That is true. But if the programmer is wrong and writes "return 0;" in
>> the wrong place, things could go equally badly.
>
> Not there though; somewhere farther down the road where the can has
> been kicked. But yes.

If the problem manifests itself later, it can be harder to find. With
"unreachable();", compilers can support debugging options to help if
you've made an error and the line is /not/ unreachable. And if they
don't have convenient debugging options, it's also easy to use a macro
here, then redefine the macro to print an error and call abort() when
fault-finding. Tracing a mistaken "return 0;" is a lot harder.

>
>> When programmers write
>> the wrong thing, bad things may happen - that's inevitable in
>> programming. One way to minimise the risk of that is by writing code
>> that makes sense - say what the code does, such as writing
>> "unreachable();" when you know that line cannot be reached, rather than
>> writing nonsense such as "return 0;" when the code cannot return from there.
>
> Or abort() when that makes sense; like that it would be bad for that
> code to be reached, and we don't think it is, but we are not so
> committed to that proposition that we're willing to bet on it with
> undefined behavior. And we don't mind the extra instructions for that in
> that situation.
>

Write "abort();" if that's what you want. But it is not an extra
instruction - it is much more invasive than that in many cases. It can
turn what would be a simple inlined function, or a "pure" function (one
that has no side effects, and whose return value is solely and
consistently dependent on the parameters) into a semantically far more
complicated function that can have major effects.

Re: bart again (UCX64)

<udi8i5$52sl$4@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: bart again (UCX64)
Date: Sat, 9 Sep 2023 19:04:05 +0200
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <udi8i5$52sl$4@dont-email.me>
References: <1262755563@f172.n1.z21.fsxnet>
<A5pKM.1180698$TPw2.694138@fx17.iad>
<87h6o51rts.fsf@nosuchdomain.example.com> <GWwKM.320358$uLJb.75975@fx41.iad>
<87y1hhmehf.fsf@nosuchdomain.example.com> <20230907235623.619@kylheku.com>
<udeksu$3crce$1@dont-email.me>
<4945f15a-22dd-431e-a732-81ed36615f27n@googlegroups.com>
<udepd1$3dal1$2@dont-email.me> <udeqdh$3dhqr$1@dont-email.me>
<20230908184633.897@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 9 Sep 2023 17:04:05 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="010d235d15fa84e76a575c550a4815f1";
logging-data="166805"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19v+n7d2mmZBI0LpeZMcGW8rwCL4RVweJE="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Cancel-Lock: sha1:g2IkFxZyWZ8micazLGSXmfPh2EU=
Content-Language: en-GB
In-Reply-To: <20230908184633.897@kylheku.com>
 by: David Brown - Sat, 9 Sep 2023 17:04 UTC

On 09/09/2023 03:48, Kaz Kylheku wrote:
> On 2023-09-08, Bart <bc@freeuk.com> wrote:
>> It's funny that some people don't want the bother of writing 'return 0;'
>> in a path they know will never be reached, while others are prepared to
>> write 'unreachable();', which is both longer and uses shifted characters.
>
> What is worse, the original program with a missing "return 0;" might
> well be correct. If the caller doesn't extract the return value,
> everything is copacetic.
>
> Whereas unreachable() is a gizmo whose only meaning is that it invokes
> undefined behavior if executed!
>
> It's like you have a pepper shaker on your programing table labeled
> "UB", and you sprinkle that on your program.
>

That's the joy of undefined behaviour :-)

Several years back, I had to deal with finding bugs in a code base where
the programmer had regularly muddled up function parameters and return
types. Most people like to have global functions declared in a header,
and include that header in the C file that defines the function and any
C files that use the function - then they get everything nice and
consistent. The code base that this programmer had started with, before
he screwed around with it, was organised like that. (I know - I wrote
it, and my gcc setup will complain loudly if there are any missing or
mismatched declarations.) But this guy frequently didn't bother
including headers, or declaring his global functions in headers.
Sometimes he had an extern declaration in the C file, sometimes he
relied on ancient implicit function declaration. And he got it wrong -
a lot. Functions would be defined with one set of parameters, and
called from different C files with a different number or different type
of parameters. Return types were equally random.

But you can't just replace a missing "return x;" with "return 0;", even
though the behaviour is defined. Sometimes the code without the return
statement works by sheer luck, which the "return 0;" is a guaranteed and
consistent failure.

It had one feature I've never seen before, tying in with another thread
here - it called main() recursively. From within an interrupt handler.

Pages:12345
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor