Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"The only way for a reporter to look at a politician is down." -- H. L. Mencken


devel / comp.lang.c / Re: Libraries using longjmp for error handling

SubjectAuthor
* Libraries using longjmp for error handling (was: Re: More on NNTPBlue-Maned_Hawk
+* Re: Libraries using longjmp for error handling (was: Re: More on NNTPJohann 'Myrkraverk' Oskarsson
|`* Re: Libraries using longjmp for error handlingBen Bacarisse
| +* Re: Libraries using longjmp for error handlingBlue-Maned_Hawk
| |`* Re: Libraries using longjmp for error handlingScott Lurndal
| | +* Re: Libraries using longjmp for error handlingAnton Shepelev
| | |`- Re: Libraries using longjmp for error handlingScott Lurndal
| | `* Re: Libraries using longjmp for error handlingKeith Thompson
| |  `- Re: Libraries using longjmp for error handlingDavid Brown
| `* Re: Libraries using longjmp for error handlingTim Rentsch
|  `* Re: Libraries using longjmp for error handlingBen Bacarisse
|   `* Re: Libraries using longjmp for error handlingTim Rentsch
|    +* Re: Libraries using longjmp for error handlingBen Bacarisse
|    |`* Re: Libraries using longjmp for error handlingTim Rentsch
|    | `* Re: Libraries using longjmp for error handlingBen Bacarisse
|    |  `* Re: Libraries using longjmp for error handlingTim Rentsch
|    |   +- Re: Libraries using longjmp for error handlingAnton Shepelev
|    |   `* Re: Libraries using longjmp for error handlingBen Bacarisse
|    |    `* Re: Libraries using longjmp for error handlingTim Rentsch
|    |     `* Re: Libraries using longjmp for error handlingBen Bacarisse
|    |      `* Re: Libraries using longjmp for error handlingTim Rentsch
|    |       `* Re: Libraries using longjmp for error handlingBen Bacarisse
|    |        `- Re: Libraries using longjmp for error handlingTim Rentsch
|    `* Re: Libraries using longjmp for error handlingAnton Shepelev
|     `* Re: Libraries using longjmp for error handlingTim Rentsch
|      `- Re: Libraries using longjmp for error handlingAnton Shepelev
+- Re: Libraries using longjmp for error handlingBen Bacarisse
+* Re: Libraries using longjmp for error handling (was: Re: More onKaz Kylheku
|`- Re: Libraries using longjmp for error handling (was: Re: More onKaz Kylheku
+* Re: Libraries using longjmp for error handling (was: Re: More onAnton Shepelev
|`* Re: Libraries using longjmp for error handlingBen Bacarisse
| `* Re: Libraries using longjmp for error handlingAnton Shepelev
|  +* Re: Libraries using longjmp for error handlingKaz Kylheku
|  |+* Re: Libraries using longjmp for error handlingScott Lurndal
|  ||+- Re: Libraries using longjmp for error handlingKaz Kylheku
|  ||`- Re: Libraries using longjmp for error handlingBen Bacarisse
|  |`* Re: Libraries using longjmp for error handlingTim Rentsch
|  | +* Re: Libraries using longjmp for error handlingKaz Kylheku
|  | |`- Re: Libraries using longjmp for error handlingTim Rentsch
|  | `* Re: Libraries using longjmp for error handlingKeith Thompson
|  |  +* Re: Libraries using longjmp for error handlingBen Bacarisse
|  |  |`- Re: Libraries using longjmp for error handlingKaz Kylheku
|  |  `* Re: Libraries using longjmp for error handlingTim Rentsch
|  |   +* Re: Libraries using longjmp for error handlingSpiros Bousbouras
|  |   |+* Re: Libraries using longjmp for error handlingTim Rentsch
|  |   ||+* Re: Libraries using longjmp for error handlingBen Bacarisse
|  |   |||+- Re: Libraries using longjmp for error handlingTim Rentsch
|  |   |||`- Re: Libraries using longjmp for error handlingKenny McCormack
|  |   ||`- Re: Libraries using longjmp for error handlingKaz Kylheku
|  |   |`* Re: Libraries using longjmp for error handlingAnton Shepelev
|  |   | `* Re: Libraries using longjmp for error handlingTim Rentsch
|  |   |  `- Re: Libraries using longjmp for error handlingKeith Thompson
|  |   `- Re: Libraries using longjmp for error handlingKaz Kylheku
|  +* Re: Libraries using longjmp for error handlingBen Bacarisse
|  |`* Re: Libraries using longjmp for error handlingKaz Kylheku
|  | `* Re: Libraries using longjmp for error handlingBen Bacarisse
|  |  +- Re: Libraries using longjmp for error handlingTim Rentsch
|  |  `* Re: Libraries using longjmp for error handlingKaz Kylheku
|  |   `* Re: Libraries using longjmp for error handlingAnton Shepelev
|  |    `- Re: Libraries using longjmp for error handlingTim Rentsch
|  `- Re: Libraries using longjmp for error handlingDavid Brown
`- Re: Libraries using longjmp for error handlingRichard Kettlewell

Pages:123
Re: Libraries using longjmp for error handling

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

  copy mid

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

  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: Libraries using longjmp for error handling
Date: Thu, 28 Sep 2023 17:35:53 -0700
Organization: None to speak of
Lines: 31
Message-ID: <87edihstna.fsf@nosuchdomain.example.com>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<AE3RM.402236$kCld.195109@fx08.ams4> <871qejf62x.fsf@bsb.me.uk>
<pan$b83bb$766eb4cb$b79b4acf$fdd8021c@invalid.invalid>
<PanRM.9358$Sn81.8479@fx08.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="1fa6e41457ad27ef0d3a035f975e01f4";
logging-data="4133271"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+sCxCKKad8UGyjDCFhZrgU"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:HEvkkTum3Ek3dGve2IAOKYhDIZE=
sha1:gPU1zKqaFSgstn1up4ZgmJyyKGk=
 by: Keith Thompson - Fri, 29 Sep 2023 00:35 UTC

scott@slp53.sl.home (Scott Lurndal) writes:
> Blue-Maned_Hawk <bluemanedhawk@invalid.invalid> writes:
>>Ben Bacarisse wrote:
>>> Haskell does not always get it right (particularly some of the older
>>> APIs) but the trend is to provide return type rich enough to include
>>> either a correct result or an explanation of the fault.
>>
>>Things like that are pretty much what i was referring to earlier when i
>>referred to making the return type more complex to handle more complex
>>situations. Obviously, it would have to be done differently in C, since C
>>doesn't support tagged unions (at least not natively—i know of a couple
>>libraries that use macro magic to implement them).
>
> In C++, a std::pair<bool, return-type> is used in that context. If the sizeof
> the return type is 64-bits or less, most modern ABI's will return it in a pair
> of registers.

<OT>
A std::pair<bool, return-type> gives you either a true value and a value
of the return type or a false value and a value of the return type.
There's no indication in the type itself that the second member is
meaningless if the first is false.

std::optional<return-type> is a better fit -- but it isn't available if
you have to deal with pre-C++17 compilers.
</OT>

--
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: Libraries using longjmp for error handling

<86y1gphiur.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Thu, 28 Sep 2023 18:24:28 -0700
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <86y1gphiur.fsf@linuxsc.com>
References: <65SQM.565977$9o89.411905@fx05.ams4> <wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk> <pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid> <AE3RM.402236$kCld.195109@fx08.ams4> <871qejf62x.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="13636bbb038e3a1f79d11dd50eec8409";
logging-data="4149754"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+eya+EYT1lr5UlffYDQz3XFGjaYOGJXR0="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:Aea0aWnp2r6S6oWqHq1ukdoDajk=
sha1:QVJEb/oWnd5aIxEtrhCbFinMUXc=
 by: Tim Rentsch - Fri, 29 Sep 2023 01:24 UTC

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

> Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> writes:
>
>> On 9/28/2023 6:52 AM, Blue-Maned_Hawk wrote:
>>
>>> Personally, i think that, at least for a library, an error
>>> should _only_ be communicated by return value. If more complex
>>> information is required, then the return value can be made more
>>> complex.
>
> ...
>
>> Error handling in libraries is a thorny subject, and I could go
>> on a long rant on it. The short summary is simply this: error
>> handling is rife with incompetence, and incompetent designs.
>> Even in languages that ostensibly provide better mechanisms than
>> C, the details are usually poorly documented and under-specified
>> [1].
>
> If it's done well, the result is not even "error handling" -- it's
> just what the function returns. For example, a lookup in a table
> of integers in Haskell returns a type that is, in effect "maybe an
> integer" The return will be either "Nothing" or something like
> "Just 42".

In languages that support it this approach is a good way to deal
with cases like this, I agree. But to me it falls in a different
category than error handling. An error condition is something
like an allocation (eg malloc()) failure, or a broken pipe. Not
finding something in a table means whoever was responsible for
adding things to the table didn't add it - in other words it was
entirely a consequence of events that are under the program's
control. The issue is how to deal with an unpredictable, and
usually very rare, event that is not something the program has
control over. Typically these kinds of situations need a
different sort of mechanism than loading up the return value
of every function call.

Re: Libraries using longjmp for error handling

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

  copy mid

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

  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: Libraries using longjmp for error handling
Date: Thu, 28 Sep 2023 18:31:32 -0700
Organization: None to speak of
Lines: 44
Message-ID: <87a5t5sr2j.fsf@nosuchdomain.example.com>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<20230928160237.9796f1896cb0be293bd24b76@gmail.moc>
<87jzsae7jm.fsf@bsb.me.uk>
<20230928183129.fb386b543c40cd56340ca40f@gmail.moc>
<20230928093424.111@kylheku.com> <8634yxj3uh.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="1fa6e41457ad27ef0d3a035f975e01f4";
logging-data="4151813"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Xg5zIlQU0ScxAQQyJX/2+"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:Xfr11dpPd7CN/Tl9DptjHSpW/tI=
sha1:w8yzofyB9ozujcRUPSz28GHFRG8=
 by: Keith Thompson - Fri, 29 Sep 2023 01:31 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> Kaz Kylheku <864-117-4973@kylheku.com> writes:
>
>> On 2023-09-28, Anton Shepelev <anton.txt@gmail.moc> wrote:
>>
>>> Ben Bacarisse to Anton Shepelev:
>>>
>>>> To nit-pick a bit, in C, there is no need to declare
>>>> anything if you want to ignore an "output parameter".
>>>> Taking strtod as a (poor) example:
>>>>
>>>> double d = strtod(str, &(char *){0});
>>>
>>> Ah, but this is one of the strangest and craziest
>>> innovations of post-modern C -- the ability to pass a
>>> pointer (as it were) to a literal, rather than to a proper
>>> variable.
>>
>> Two things:
>>
>> Firstly, it's not a true literal because it is a mutable object in
>> automatic storage.
>
> It most definitely is a literal, both in the original meaning
> of the word, and also as used in the ISO C standard.

C doesn't not define what the word "literal" means. It has no syntactic
category called "literal". It has distinct constructs "string literal"
and "compound literal".

You've asserted in the past that there's a logical reason behind using
the term "literal" for these two constructs and not for others, such as
integer constants. I'm not particularly interested in debating that
point again, but I see no support in the standard for that assertion.
(The standard also uses the word "literal" as an adjective; see for
example N1570 6.1p1 where it refers to terminals in the grammar.)

My point is that any discussion of what is or is not a "true literal" is
unlikely to yield any meaningful result.

--
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: Libraries using longjmp for error handling

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

  copy mid

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

  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: Libraries using longjmp for error handling
Date: Fri, 29 Sep 2023 03:19:17 +0100
Organization: A noiseless patient Spider
Lines: 67
Message-ID: <877co9d8m2.fsf@bsb.me.uk>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<AE3RM.402236$kCld.195109@fx08.ams4> <871qejf62x.fsf@bsb.me.uk>
<86y1gphiur.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="4dfdf850a714e5d3717da460fbf945f6";
logging-data="97997"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/MA5j8x6wrbx2Gn37U4wMDeA6U/M13As8="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:X0rgYxHHQvVk3KQbBtfCc6RWdNE=
sha1:jEqYTiIPRj3vvSO6qdZiIABVdiM=
X-BSB-Auth: 1.732c69ec819d688577de.20230929031917BST.877co9d8m2.fsf@bsb.me.uk
 by: Ben Bacarisse - Fri, 29 Sep 2023 02:19 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:

> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>
>> Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> writes:
>>
>>> On 9/28/2023 6:52 AM, Blue-Maned_Hawk wrote:
>>>
>>>> Personally, i think that, at least for a library, an error
>>>> should _only_ be communicated by return value. If more complex
>>>> information is required, then the return value can be made more
>>>> complex.
>>
>> ...
>>
>>> Error handling in libraries is a thorny subject, and I could go
>>> on a long rant on it. The short summary is simply this: error
>>> handling is rife with incompetence, and incompetent designs.
>>> Even in languages that ostensibly provide better mechanisms than
>>> C, the details are usually poorly documented and under-specified
>>> [1].
>>
>> If it's done well, the result is not even "error handling" -- it's
>> just what the function returns. For example, a lookup in a table
>> of integers in Haskell returns a type that is, in effect "maybe an
>> integer" The return will be either "Nothing" or something like
>> "Just 42".
>
> In languages that support it this approach is a good way to deal
> with cases like this, I agree. But to me it falls in a different
> category than error handling. An error condition is something
> like an allocation (eg malloc()) failure, or a broken pipe. Not
> finding something in a table means whoever was responsible for
> adding things to the table didn't add it - in other words it was
> entirely a consequence of events that are under the program's
> control. The issue is how to deal with an unpredictable, and
> usually very rare, event that is not something the program has
> control over. Typically these kinds of situations need a
> different sort of mechanism than loading up the return value
> of every function call.

I agree that table lookup is not a compelling example, but I don't agree
that anything different is needed. I intended the idea to be
generalised to have return values used for all error conditions. There
may be situations where something different is /better/, but I remain
sceptical of even this claim. Note I am not talking about situations
where asynchronous errors need to be reported.

C uses null pointers for this all the time. Returning a null pointer is
just a way to signal an error through the return value. In a language
like C without null pointers I would want malloc to return a 'Maybe'
type. And for when more information is wanted (like your example of a
broken pipe) the type returned from write should be a number of bytes or
an error value of some sort.

Obviously it's hard to recommend this in C since the language can't
really express the patterns needed to make it convenient, but I think we
are talking more generally here.

How would you prefer these sorts of thing to be signalled?

BTW, have you come across Icon? It takes an intriguing approach where
every operation succeeds or fails as well as having a value. This idea
is heavily built upon to produce a very comfortable scripting language.

--
Ben.

Re: Libraries using longjmp for error handling

<871qehd8da.fsf@bsb.me.uk>

  copy mid

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

  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: Libraries using longjmp for error handling
Date: Fri, 29 Sep 2023 03:24:33 +0100
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <871qehd8da.fsf@bsb.me.uk>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<20230928160237.9796f1896cb0be293bd24b76@gmail.moc>
<87jzsae7jm.fsf@bsb.me.uk>
<20230928183129.fb386b543c40cd56340ca40f@gmail.moc>
<20230928093424.111@kylheku.com> <8634yxj3uh.fsf@linuxsc.com>
<87a5t5sr2j.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="4dfdf850a714e5d3717da460fbf945f6";
logging-data="97997"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/sJC+TFDpVvlLOW7pJoFVZbBwy+BRbdnU="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:bfWUp5A625vFwBCaFKhSZq864GU=
sha1:5OMvj9rl+SbM/2FL4gCkGzu8UzM=
X-BSB-Auth: 1.9e9c9e27a490b8500013.20230929032433BST.871qehd8da.fsf@bsb.me.uk
 by: Ben Bacarisse - Fri, 29 Sep 2023 02:24 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>> Kaz Kylheku <864-117-4973@kylheku.com> writes:
>>
>>> On 2023-09-28, Anton Shepelev <anton.txt@gmail.moc> wrote:
>>>
>>>> Ben Bacarisse to Anton Shepelev:
>>>>
>>>>> To nit-pick a bit, in C, there is no need to declare
>>>>> anything if you want to ignore an "output parameter".
>>>>> Taking strtod as a (poor) example:
>>>>>
>>>>> double d = strtod(str, &(char *){0});
>>>>
>>>> Ah, but this is one of the strangest and craziest
>>>> innovations of post-modern C -- the ability to pass a
>>>> pointer (as it were) to a literal, rather than to a proper
>>>> variable.
>>>
>>> Two things:
>>>
>>> Firstly, it's not a true literal because it is a mutable object in
>>> automatic storage.
>>
>> It most definitely is a literal, both in the original meaning
>> of the word, and also as used in the ISO C standard.
>
> C doesn't not define what the word "literal" means. It has no syntactic
> category called "literal". It has distinct constructs "string literal"
> and "compound literal".
>
> You've asserted in the past that there's a logical reason behind using
> the term "literal" for these two constructs and not for others, such as
> integer constants. I'm not particularly interested in debating that
> point again, but I see no support in the standard for that assertion.
> (The standard also uses the word "literal" as an adjective; see for
> example N1570 6.1p1 where it refers to terminals in the grammar.)
>
> My point is that any discussion of what is or is not a "true literal" is
> unlikely to yield any meaningful result.

I agree, though it might be interesting to see if

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

sheds any light on the usage. This document is one of the standard's
"Normative References". I don't have this document, nor do I have access
to the right sort of library any more, so I can't help.

--
Ben.

Re: Libraries using longjmp for error handling

<20230928200741.77@kylheku.com>

  copy mid

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

  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: Libraries using longjmp for error handling
Date: Fri, 29 Sep 2023 03:12:54 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <20230928200741.77@kylheku.com>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<20230928160237.9796f1896cb0be293bd24b76@gmail.moc>
<87jzsae7jm.fsf@bsb.me.uk>
<20230928183129.fb386b543c40cd56340ca40f@gmail.moc>
<20230928093424.111@kylheku.com> <8634yxj3uh.fsf@linuxsc.com>
<87a5t5sr2j.fsf@nosuchdomain.example.com> <871qehd8da.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 29 Sep 2023 03:12:54 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3e2464a16a598f67870a96179f3b3745";
logging-data="111027"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/D05Kld7o04T/DbDzRrfEJMlL/yb0Q2x4="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:HLBxezqRixbEoeCSmd0jaMMAdW8=
 by: Kaz Kylheku - Fri, 29 Sep 2023 03:12 UTC

On 2023-09-29, Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>> My point is that any discussion of what is or is not a "true literal" is
>> unlikely to yield any meaningful result.
>
> I agree, though it might be interesting to see if
>
> ISO/IEC 2382−1:1993, Information technology — Vocabulary — Part 1:
> Fundamental terms.
>
> sheds any light on the usage. This document is one of the standard's
> "Normative References". I don't have this document, nor do I have access
> to the right sort of library any more, so I can't help.

FYI, I looked at this quite long ago. At that time I hunted down a
leaked version which is under a different number:
IS 14692-1 (1999). IS == Indian Standard.

I see that this can still be found.

The document does not mention "literal".

You will likely agree with my observation that the document is rather
short, and lacks substance.

--
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: Libraries using longjmp for error handling

<86lecph6rv.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Thu, 28 Sep 2023 22:45:24 -0700
Organization: A noiseless patient Spider
Lines: 71
Message-ID: <86lecph6rv.fsf@linuxsc.com>
References: <65SQM.565977$9o89.411905@fx05.ams4> <wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk> <pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid> <20230928160237.9796f1896cb0be293bd24b76@gmail.moc> <87jzsae7jm.fsf@bsb.me.uk> <20230928183129.fb386b543c40cd56340ca40f@gmail.moc> <20230928093424.111@kylheku.com> <8634yxj3uh.fsf@linuxsc.com> <87a5t5sr2j.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="13636bbb038e3a1f79d11dd50eec8409";
logging-data="154330"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX198WwT7hXUSaIfl3JFJBp3fU05GYcmA/oY="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:BKcSqH0OqPgM3gpUkoGyD1xD/sU=
sha1:YntD5pACYHRqAxuU0Q604Qzww2Q=
 by: Tim Rentsch - Fri, 29 Sep 2023 05:45 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>
>> Kaz Kylheku <864-117-4973@kylheku.com> writes:
>>
>>> On 2023-09-28, Anton Shepelev <anton.txt@gmail.moc> wrote:
>>>
>>>> Ben Bacarisse to Anton Shepelev:
>>>>
>>>>> To nit-pick a bit, in C, there is no need to declare
>>>>> anything if you want to ignore an "output parameter".
>>>>> Taking strtod as a (poor) example:
>>>>>
>>>>> double d = strtod(str, &(char *){0});
>>>>
>>>> Ah, but this is one of the strangest and craziest
>>>> innovations of post-modern C -- the ability to pass a
>>>> pointer (as it were) to a literal, rather than to a proper
>>>> variable.
>>>
>>> Two things:
>>>
>>> Firstly, it's not a true literal because it is a mutable object in
>>> automatic storage.
>>
>> It most definitely is a literal, both in the original meaning
>> of the word, and also as used in the ISO C standard.
>
> C doesn't not define what the word "literal" means. It has no
> syntactic category called "literal". It has distinct constructs
> "string literal" and "compound literal".

I didn't say the C standard defines the term literal, only that
the standard uses the word literal in the same sense as the
original meaning. (To be clear, the uses I'm talking about are
as part of compound terms "string literal" and "compound literal",
but the sense of common meaning is the same in both.)

It's true that string literals and compound literals are
different constructs, but they are obviously related, and they
are referred to together in a few places in the C standard.

> You've asserted in the past that there's a logical reason behind
> using the term "literal" for these two constructs and not for
> others, such as integer constants. I'm not particularly interested
> in debating that point again, but I see no support in the standard
> for that assertion. (The standard also uses the word "literal" as
> an adjective; see for example N1570 6.1p1 where it refers to
> terminals in the grammar.)

I don't have my previous posting in front of me, but what I think
I said is that string literals and compound literals are both
consistent with the original meaning (in the programming world)
of the word literal, and that other constructs such as integer
constants do not share that aspect of semantic sameness. Also
IIRC I stated my view that the semantic distinction is more
valuable than a possible syntactic distinction, and so that is
worth preserving, i.e., that string literals and compound
literals deserve to be associated with the term "literal", but
constants should not.

> My point is that any discussion of what is or is not a "true
> literal" is unlikely to yield any meaningful result.

I'm not saying anything about whether something is a "true
literal", whatever that might be. What I am saying is that
a compound literal is a literal in the same sense that the
term was originally used, and that sense is consistent with
both string literals and compound literals (but not with
constants such as integer constants or floating constants).

Re: Libraries using longjmp for error handling

<86h6ndh55s.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Thu, 28 Sep 2023 23:20:15 -0700
Organization: A noiseless patient Spider
Lines: 74
Message-ID: <86h6ndh55s.fsf@linuxsc.com>
References: <65SQM.565977$9o89.411905@fx05.ams4> <wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk> <pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid> <20230928160237.9796f1896cb0be293bd24b76@gmail.moc> <87jzsae7jm.fsf@bsb.me.uk> <20230928183129.fb386b543c40cd56340ca40f@gmail.moc> <20230928093424.111@kylheku.com> <8634yxj3uh.fsf@linuxsc.com> <20230928161154.506@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="13636bbb038e3a1f79d11dd50eec8409";
logging-data="165539"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18GfIrnA8dKv7dLyoXptYa9lZyq9aiF7X4="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:/hcBgkf5eAnSkL+8+FBVYW9YMRI=
sha1:PZR2Xj/rGOwZjdq2yK1u8C8+YqE=
 by: Tim Rentsch - Fri, 29 Sep 2023 06:20 UTC

Kaz Kylheku <864-117-4973@kylheku.com> writes:

> On 2023-09-28, Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
>
>> Kaz Kylheku <864-117-4973@kylheku.com> writes:
>>
>>> On 2023-09-28, Anton Shepelev <anton.txt@gmail.moc> wrote:
>>>
>>>> Ben Bacarisse to Anton Shepelev:
>>>>
>>>>> To nit-pick a bit, in C, there is no need to declare
>>>>> anything if you want to ignore an "output parameter".
>>>>> Taking strtod as a (poor) example:
>>>>>
>>>>> double d = strtod(str, &(char *){0});
>>>>
>>>> Ah, but this is one of the strangest and craziest
>>>> innovations of post-modern C -- the ability to pass a
>>>> pointer (as it were) to a literal, rather than to a proper
>>>> variable.
>>>
>>> Two things:
>>>
>>> Firstly, it's not a true literal because it is a mutable object in
>>> automatic storage.
>>
>> It most definitely is a literal, both in the original meaning
>
> Let's examine our use of the article "a".
>
> #include <stdio.h>
>
> void fun(int c)
> {
> char x;
>
> if (c > 0) {
> printf("%p\n", (void *) &(char *){&x});
> fun(c - 1);
> }
> }
>
> [...]

> What is literal about it?

It refers an anonymous object whose initial value is determined
by the tokens making up the literal. That meaning of the term
"literal" is about 60 years old. (That meaning didn't use the
word "object" but did refer to memory that in the context of
the C standard would be called an object.)

> C99 said that a compound literal "is an expression that
> provides access to an anonymous object".
>
> Why can't we call that expression "anonymous object designator"
> or something? If we have "char *p = 0", p is a primary
> expression which designates an object, and not a literal.

You could call it a rhinoceros if you wanted to, but that
wouldn't change what the C standard calls it, or what the
original meaning of the word literal is, or that both the
term compound literal and the orginal meaning of literal
share the key property of referring to an anonymous object.

> If we then have (char *){p} we get an anonymous object that is
> initialized with a copy of p, and that expression designates it
> in much the same way as p designates its object.

They differ in one key respect: in the case of a variable, we
have to give the variable a name, and refer to the object by its
name, but in the case of a compound literal, there is no name,
and we refer to the object "by what it is". That's why it's
called a literal.

Re: Libraries using longjmp for error handling

<owGlRX9UheAv7IQ6v@bongo-ra.co>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: spi...@gmail.com (Spiros Bousbouras)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Fri, 29 Sep 2023 12:02:35 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <owGlRX9UheAv7IQ6v@bongo-ra.co>
References: <65SQM.565977$9o89.411905@fx05.ams4> <wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk> <pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<20230928160237.9796f1896cb0be293bd24b76@gmail.moc> <87jzsae7jm.fsf@bsb.me.uk> <20230928183129.fb386b543c40cd56340ca40f@gmail.moc>
<20230928093424.111@kylheku.com> <8634yxj3uh.fsf@linuxsc.com> <87a5t5sr2j.fsf@nosuchdomain.example.com>
<86lecph6rv.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 29 Sep 2023 12:02:35 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c06532b8e0fab7b5135e762a103a8dc4";
logging-data="290555"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ZCpAVnJFjmQIP1r+mUgIc"
Cancel-Lock: sha1:IAo/bFaSRdutpDCZOuycjAdvr88=
In-Reply-To: <86lecph6rv.fsf@linuxsc.com>
X-Organisation: Weyland-Yutani
X-Server-Commands: nowebcancel
 by: Spiros Bousbouras - Fri, 29 Sep 2023 12:02 UTC

On Thu, 28 Sep 2023 22:45:24 -0700
Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
> > You've asserted in the past that there's a logical reason behind
> > using the term "literal" for these two constructs and not for
> > others, such as integer constants. I'm not particularly interested
> > in debating that point again, but I see no support in the standard
> > for that assertion. (The standard also uses the word "literal" as
> > an adjective; see for example N1570 6.1p1 where it refers to
> > terminals in the grammar.)
>
> I don't have my previous posting in front of me,

<86r0o887op.fsf@linuxsc.com> and <86fs4k6pgq.fsf@linuxsc.com> .

Re: Libraries using longjmp for error handling

<20230929172303.8828ee9f53666282c58bdb0a@gmail.moc>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton....@gmail.moc (Anton Shepelev)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Fri, 29 Sep 2023 17:23:03 +0300
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <20230929172303.8828ee9f53666282c58bdb0a@gmail.moc>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<20230928160237.9796f1896cb0be293bd24b76@gmail.moc>
<87jzsae7jm.fsf@bsb.me.uk>
<20230928183129.fb386b543c40cd56340ca40f@gmail.moc>
<878r8qdufu.fsf@bsb.me.uk>
<20230928130843.804@kylheku.com>
<87il7uc7q4.fsf@bsb.me.uk>
<20230928155123.960@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="e1aa748db48c5806684f03ca245fb41b";
logging-data="346460"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/igOsewq2egbhzhIrHFgOVxig0mTqXslQ="
Cancel-Lock: sha1:qtrCwwhNBeJ9RKKaQs/rsuT8jSA=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
 by: Anton Shepelev - Fri, 29 Sep 2023 14:23 UTC

Kaz Kylheku to Ben Bacarisse:

> > OK, I see the point -- the ptr member in the returned
> > value is sort of an anonymous object -- but in my
> > opinion it's a stretch.
>
> I think the point is that Anton should find the existence
> of all anoymous temporary objects repugnant, not just the
> more recently introduced ones.

In that case, I see it as more or less a named object, its
name being the `ptr' field qualified by the function
invocation. Otherwise, I should find repugnant even simple
expressions, like:

res = sqr(x) + sqr(y);

where the return value of sqr() is techically some sort of
anonymous object, right? Well, I do not object to functions
invocations in exprssions, for the reason stated above, and
because the are similar to the universally understood
mathematical notation.

> That's why I put this under the "strange and crazy
> innovations in post-modern C" remarks.

Right. Many of you will tell me that I have to bend my
mental model to reflect the workings of C rather than trying
to bend C (e.g. by avoiding some techniques) to comply with
my mental model.

--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments

Re: Libraries using longjmp for error handling

<86bkdlghqr.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Fri, 29 Sep 2023 07:46:04 -0700
Organization: A noiseless patient Spider
Lines: 129
Message-ID: <86bkdlghqr.fsf@linuxsc.com>
References: <65SQM.565977$9o89.411905@fx05.ams4> <wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk> <pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid> <AE3RM.402236$kCld.195109@fx08.ams4> <871qejf62x.fsf@bsb.me.uk> <86y1gphiur.fsf@linuxsc.com> <877co9d8m2.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="13636bbb038e3a1f79d11dd50eec8409";
logging-data="355036"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX191BicX5xTTA9RB/8kEe9ihViQi/5avXys="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:mce0er11/zN9MR4s+nIldCQq93o=
sha1:zBgpeknVTyz0D/XP/XORAmfmW38=
 by: Tim Rentsch - Fri, 29 Sep 2023 14:46 UTC

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

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>
>> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>>

[..how should errors be handled..]

>>> If it's done well, the result is not even "error handling" -- it's
>>> just what the function returns. For example, a lookup in a table
>>> of integers in Haskell returns a type that is, in effect "maybe an
>>> integer" The return will be either "Nothing" or something like
>>> "Just 42".
>>
>> In languages that support it this approach is a good way to deal
>> with cases like this, I agree. But to me it falls in a different
>> category than error handling. An error condition is something
>> like an allocation (eg malloc()) failure, or a broken pipe. Not
>> finding something in a table means whoever was responsible for
>> adding things to the table didn't add it - in other words it was
>> entirely a consequence of events that are under the program's
>> control. The issue is how to deal with an unpredictable, and
>> usually very rare, event that is not something the program has
>> control over. Typically these kinds of situations need a
>> different sort of mechanism than loading up the return value
>> of every function call.
>
> I agree that table lookup is not a compelling example, but I don't
> agree that anything different is needed. I intended the idea to
> be generalised to have return values used for all error
> conditions. There may be situations where something different is
> /better/, but I remain sceptical of even this claim. Note I am
> not talking about situations where asynchronous errors need to be
> reported.
>
> C uses null pointers for this all the time. Returning a null
> pointer is just a way to signal an error through the return value.
> In a language like C without null pointers I would want malloc to
> return a 'Maybe' type. And for when more information is wanted
> (like your example of a broken pipe) the type returned from write
> should be a number of bytes or an error value of some sort.
>
> Obviously it's hard to recommend this in C since the language
> can't really express the patterns needed to make it convenient,
> but I think we are talking more generally here.

I acknowledge your statement about not considering asynchronous
errors. My own comments are likewise.

I agree that all unusual result circumstances (which might be
labeled "error conditions", without meaning to prejudice the term)
can be handled locally via either compound return values or multiple
return values (eg, by using pointer parameters), or a combination of
the two. In languages that provide good support for compound return
values, which I would say C does not, probably a single return value
(which is perhaps a compound value) always suffices, but I haven't
thought very carefully about that. But I think we are in general
agreement that it's always possible to handle error conditions via
local return values.

Where we might not agree is whether using direct return values is
always a good choice. In my view, sometimes it is, sometimes it
isn't - it depends on the particular situation. That is definitely
the case for C, but I think also for other programming languages
that have better support for multiple return values or compound
return values, or both. And certainly if needing other mechanisms
is true for languages in general then it we would expect it is true
for C.

> How would you prefer these sorts of thing to be signalled?

Let me give just one example.

kI wrote some code not long ago to add a value to a set of values,
where the set is represented using a recursive binary tree structure
(like red-black trees, but a little different). Usually we may
expect that a request to add a value would offer a value not already
included in the set, but certainly it can happen that there is a
call to add a value that is already included, in which case the top
level return value should be the original tree structure.

I thought it would be easier to write a simple recursive routine
that assumes the to-be-added value is not yet included in the set,
and if that assumption is violated raise an exception that is caught
at the outermost level and simply returns the original argument tree
value. Certainly the code could have been written to handle the
already-present situation at each level of the recursion, but it was
much easier and much cleaner to handle it by raising an exception.

That example doesn't translate to C in any obvious way, because C
code to add items to a set would very likely be written rather
differently. I think it's harder to make use of non-local returns
in C than in many other languages, because C requires more thought
and discipline to set that up. At the same time, when I look at C
code that tries to handle all exceptional conditions locally, I
can't help but think the code would be simplified overall if code
for dealing with exceptional conditions could be removed in the code
generally and instead used a different mechanism, in fewer places,
and perhaps similar to raising an exception, to handle such cases.

> BTW, have you come across Icon?

I have, and it's a fascinating language.

> It takes an intriguing approach
> where every operation succeeds or fails as well as having a value.

I have heard Icon characterized as saying "it tries to succeed",
and I think that's a fair description. The idea of integrating
a backtracking engine into the language semantics deserves more
attention than I think it has been given, which is unfortunate.

> This idea is heavily built upon to produce a very comfortable
> scripting language.

My experience with Icon is purely academic, which is to say I have
read about it but never used it. I have more experience with
Prolog, which is similar in some ways (notably backtracking) but of
course very different in other ways.

I'm intrigued by your comment that Icon makes a good scripting
language. Maybe I don't understand what you think makes a good
scripting language, or even what "scripting language" means.
That subject is not topical in comp.lang.c, but I also peruse
comp.lang.misc and comp.programming if you wouldn't mind
continuing there. Also you are welcome to send me an email
at this address if you would rather do that.

Re: Libraries using longjmp for error handling

<uf6o5c$ark0$1@dont-email.me>

  copy mid

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

  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: Libraries using longjmp for error handling
Date: Fri, 29 Sep 2023 16:49:16 +0200
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <uf6o5c$ark0$1@dont-email.me>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<AE3RM.402236$kCld.195109@fx08.ams4> <871qejf62x.fsf@bsb.me.uk>
<pan$b83bb$766eb4cb$b79b4acf$fdd8021c@invalid.invalid>
<PanRM.9358$Sn81.8479@fx08.iad> <87edihstna.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 29 Sep 2023 14:49:16 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ded4d74c929c2cc353f34cfe04647677";
logging-data="355968"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+mbHaNd8H5aFPd/7UvQJ5Gi9fq8xBlVwc="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:6G1TOif2cbX7uWqGavt/zOZ9oi0=
Content-Language: en-GB
In-Reply-To: <87edihstna.fsf@nosuchdomain.example.com>
 by: David Brown - Fri, 29 Sep 2023 14:49 UTC

On 29/09/2023 02:35, Keith Thompson wrote:
> scott@slp53.sl.home (Scott Lurndal) writes:
>> Blue-Maned_Hawk <bluemanedhawk@invalid.invalid> writes:
>>> Ben Bacarisse wrote:
>>>> Haskell does not always get it right (particularly some of the older
>>>> APIs) but the trend is to provide return type rich enough to include
>>>> either a correct result or an explanation of the fault.
>>>
>>> Things like that are pretty much what i was referring to earlier when i
>>> referred to making the return type more complex to handle more complex
>>> situations. Obviously, it would have to be done differently in C, since C
>>> doesn't support tagged unions (at least not natively—i know of a couple
>>> libraries that use macro magic to implement them).
>>
>> In C++, a std::pair<bool, return-type> is used in that context. If the sizeof
>> the return type is 64-bits or less, most modern ABI's will return it in a pair
>> of registers.
>
> <OT>
> A std::pair<bool, return-type> gives you either a true value and a value
> of the return type or a false value and a value of the return type.
> There's no indication in the type itself that the second member is
> meaningless if the first is false.
>
> std::optional<return-type> is a better fit -- but it isn't available if
> you have to deal with pre-C++17 compilers.
> </OT>
>

<OT>

std::optional<> is a standard library template that is based around a
struct containing a bool and a return type, just like a std::pair<bool,
return-type> would be. I don't think it needs C++17 to implement it - I
think you could make a reasonable bash at making an "optional" template
even in pre-C++11 C++. (I believe boost::optional works with C++03.)

But there are probably a number of nuances that make it better in modern
C++, and of course it is far more convenient when it is already in the
library. And certainly if you are using C++17, it's a better choice
here than a bare pair.

</OT>

Re: Libraries using longjmp for error handling

<86wmw9f21z.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Fri, 29 Sep 2023 08:10:16 -0700
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <86wmw9f21z.fsf@linuxsc.com>
References: <65SQM.565977$9o89.411905@fx05.ams4> <wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk> <pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid> <20230928160237.9796f1896cb0be293bd24b76@gmail.moc> <87jzsae7jm.fsf@bsb.me.uk> <20230928183129.fb386b543c40cd56340ca40f@gmail.moc> <20230928093424.111@kylheku.com> <8634yxj3uh.fsf@linuxsc.com> <87a5t5sr2j.fsf@nosuchdomain.example.com> <86lecph6rv.fsf@linuxsc.com> <owGlRX9UheAv7IQ6v@bongo-ra.co>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="13636bbb038e3a1f79d11dd50eec8409";
logging-data="358958"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19plskE6EyL64JkzQDhf5qQZ9dZ/iM9nlE="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:qlAn6TuSgHFDF2N787Zia7zuLRs=
sha1:/ES4d2Ri52mAt6HagR2vcDCa6/w=
 by: Tim Rentsch - Fri, 29 Sep 2023 15:10 UTC

Spiros Bousbouras <spibou@gmail.com> writes:

> On Thu, 28 Sep 2023 22:45:24 -0700
> Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
>
>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>
>>> You've asserted in the past that there's a logical reason behind
>>> using the term "literal" for these two constructs and not for
>>> others, such as integer constants. I'm not particularly interested
>>> in debating that point again, but I see no support in the standard
>>> for that assertion. (The standard also uses the word "literal" as
>>> an adjective; see for example N1570 6.1p1 where it refers to
>>> terminals in the grammar.)
>>
>> I don't have my previous posting in front of me,
>
> <86r0o887op.fsf@linuxsc.com> and <86fs4k6pgq.fsf@linuxsc.com> .

I know references like that are helpful for some people,
however they are not for me.[*] Thank you though for
trying to help.

[*] And I have no desire to change that, at least not any time
soon.

Re: Libraries using longjmp for error handling

<20230929181110.db35a227b46ec7e463f3801e@gmail.moc>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton....@gmail.moc (Anton Shepelev)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Fri, 29 Sep 2023 18:11:10 +0300
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <20230929181110.db35a227b46ec7e463f3801e@gmail.moc>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<20230928160237.9796f1896cb0be293bd24b76@gmail.moc>
<87jzsae7jm.fsf@bsb.me.uk>
<20230928183129.fb386b543c40cd56340ca40f@gmail.moc>
<20230928093424.111@kylheku.com>
<8634yxj3uh.fsf@linuxsc.com>
<87a5t5sr2j.fsf@nosuchdomain.example.com>
<86lecph6rv.fsf@linuxsc.com>
<owGlRX9UheAv7IQ6v@bongo-ra.co>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="e1aa748db48c5806684f03ca245fb41b";
logging-data="362411"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+AJbpaLCpdR7FxlySPOznXoIZtCw/r8DY="
Cancel-Lock: sha1:HbhNpqkk8zopQpsUyy+0ZbDClSw=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
 by: Anton Shepelev - Fri, 29 Sep 2023 15:11 UTC

Spiros Bousbouras to Tim Rentsch:

> > I don't have my previous posting in front of me,
>
> <86r0o887op.fsf@linuxsc.com> and
> <86fs4k6pgq.fsf@linuxsc.com> .

What fine Message-Id:s! Does FSF stand for the Free
Software Fondation? Tim might appreciate working URLs to
archived messages:

http://al.howardknight.net/?ID=169556843200
http://al.howardknight.net/?ID=169556849300

--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments

Re: Libraries using longjmp for error handling

<86pm21f1me.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Fri, 29 Sep 2023 08:19:37 -0700
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <86pm21f1me.fsf@linuxsc.com>
References: <65SQM.565977$9o89.411905@fx05.ams4> <wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk> <pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid> <20230928160237.9796f1896cb0be293bd24b76@gmail.moc> <87jzsae7jm.fsf@bsb.me.uk> <20230928183129.fb386b543c40cd56340ca40f@gmail.moc> <878r8qdufu.fsf@bsb.me.uk> <20230928130843.804@kylheku.com> <87il7uc7q4.fsf@bsb.me.uk> <20230928155123.960@kylheku.com> <20230929172303.8828ee9f53666282c58bdb0a@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="13636bbb038e3a1f79d11dd50eec8409";
logging-data="358958"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+vS54o8XoFo1LOULnAqDEgkdxPX24cd98="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:9xedAJDe8hvMJBnYF0DdpwFbThg=
sha1:Ka1zWPHmR6HJUuqsru3+RzZr1lA=
 by: Tim Rentsch - Fri, 29 Sep 2023 15:19 UTC

Anton Shepelev <anton.txt@gmail.moc> writes:

> Kaz Kylheku to Ben Bacarisse:
>
>>> OK, I see the point -- the ptr member in the returned
>>> value is sort of an anonymous object -- but in my
>>> opinion it's a stretch.
>>
>> I think the point is that Anton should find the existence
>> of all anoymous temporary objects repugnant, not just the
>> more recently introduced ones.
>
> In that case, I see it as more or less a named object, its
> name being the `ptr' field qualified by the function
> invocation. Otherwise, I should find repugnant even simple
> expressions, like:
>
> res = sqr(x) + sqr(y);
>
> where the return value of sqr() is techically some sort of
> anonymous object, right? [...]

No, it isn't. The result of calling sqr(x) is a value, not
an object. All objects have an address; the result of sqr(x)
does not. In an expression like 3+4, the 3 and the 4 are
values, not objects. That is one reason why the distinction
between constants, which are values and not objects, and
literals, which are anonymous objects, is important.

Re: Libraries using longjmp for error handling

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

  copy mid

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

  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: Libraries using longjmp for error handling
Date: Fri, 29 Sep 2023 17:03:13 +0100
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <87jzs9arwe.fsf@bsb.me.uk>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<20230928160237.9796f1896cb0be293bd24b76@gmail.moc>
<87jzsae7jm.fsf@bsb.me.uk>
<20230928183129.fb386b543c40cd56340ca40f@gmail.moc>
<20230928093424.111@kylheku.com> <8634yxj3uh.fsf@linuxsc.com>
<87a5t5sr2j.fsf@nosuchdomain.example.com> <86lecph6rv.fsf@linuxsc.com>
<owGlRX9UheAv7IQ6v@bongo-ra.co> <86wmw9f21z.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="4dfdf850a714e5d3717da460fbf945f6";
logging-data="379662"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19CD9EADrc9BjuWM6qIGpAgxiIGCyqbHAY="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:5+VoAYrPZDVHnCNNJFXoeHu0H2U=
sha1:1HFS5nJ7cr4WIoWs5N+F+LG0z5o=
X-BSB-Auth: 1.2d7ce3fa0a2404218137.20230929170313BST.87jzs9arwe.fsf@bsb.me.uk
 by: Ben Bacarisse - Fri, 29 Sep 2023 16:03 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:

> Spiros Bousbouras <spibou@gmail.com> writes:
>
>> On Thu, 28 Sep 2023 22:45:24 -0700
>> Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
>>
>>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>>
>>>> You've asserted in the past that there's a logical reason behind
>>>> using the term "literal" for these two constructs and not for
>>>> others, such as integer constants. I'm not particularly interested
>>>> in debating that point again, but I see no support in the standard
>>>> for that assertion. (The standard also uses the word "literal" as
>>>> an adjective; see for example N1570 6.1p1 where it refers to
>>>> terminals in the grammar.)
>>>
>>> I don't have my previous posting in front of me,
>>
>> <86r0o887op.fsf@linuxsc.com> and <86fs4k6pgq.fsf@linuxsc.com> .
>
> I know references like that are helpful for some people,
> however they are not for me.[*] Thank you though for
> trying to help.

I can't help wondering what you mean. You seem to use GNUS, as I do,
and I find such reference the most useful of all as just one click and
I'm, reading the referenced article in the same window.

> [*] And I have no desire to change that, at least not any time
> soon.

--
Ben.

Re: Libraries using longjmp for error handling

<86lecogatr.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Fri, 29 Sep 2023 10:15:28 -0700
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <86lecogatr.fsf@linuxsc.com>
References: <65SQM.565977$9o89.411905@fx05.ams4> <wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk> <pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid> <20230928160237.9796f1896cb0be293bd24b76@gmail.moc> <87jzsae7jm.fsf@bsb.me.uk> <20230928183129.fb386b543c40cd56340ca40f@gmail.moc> <20230928093424.111@kylheku.com> <8634yxj3uh.fsf@linuxsc.com> <87a5t5sr2j.fsf@nosuchdomain.example.com> <86lecph6rv.fsf@linuxsc.com> <owGlRX9UheAv7IQ6v@bongo-ra.co> <86wmw9f21z.fsf@linuxsc.com> <87jzs9arwe.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="13636bbb038e3a1f79d11dd50eec8409";
logging-data="410337"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19c8fOouZed8EXbXrH70FI1xqbAN683/tQ="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:N2aJgVE4EbUvgXG+LKLD9rLsYdI=
sha1:5tbNpU8B/ajo+KrB0te2dfQVbsY=
 by: Tim Rentsch - Fri, 29 Sep 2023 17:15 UTC

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

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>
>> Spiros Bousbouras <spibou@gmail.com> writes:

[access to previous articles]

>>> <86r0o887op.fsf@linuxsc.com> and <86fs4k6pgq.fsf@linuxsc.com> .
>>
>> I know references like that are helpful for some people,
>> however they are not for me.[*] Thank you though for
>> trying to help.
>
> I can't help wondering what you mean. You seem to use GNUS, as I
> do, and I find such reference the most useful of all as just one
> click and I'm, reading the referenced article in the same window.

I expect you are simply underestimating the depth of my ignorance.
Even though I have been using emacs for more than 40 years (and the
emacs session into which I am typing this message has been up for
more than two and half years), my knowledge of emacs commands (and
including gnus commands) is very selective. My typical working
mode is to learn just enough to get by, and accumulate new
awareness only when there is some kind of nudge to do so. So far I
haven't gotten such a nudge in the direction of this capability
(and it is not at all clear how big a nudge it would take to cause
any change).

Re: Libraries using longjmp for error handling

<uf70s1$1gt3v$1@news.xmission.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Fri, 29 Sep 2023 17:17:53 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <uf70s1$1gt3v$1@news.xmission.com>
References: <65SQM.565977$9o89.411905@fx05.ams4> <owGlRX9UheAv7IQ6v@bongo-ra.co> <86wmw9f21z.fsf@linuxsc.com> <87jzs9arwe.fsf@bsb.me.uk>
Injection-Date: Fri, 29 Sep 2023 17:17:53 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="1602687"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Fri, 29 Sep 2023 17:17 UTC

In article <87jzs9arwe.fsf@bsb.me.uk>,
Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
>Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>
>> Spiros Bousbouras <spibou@gmail.com> writes:
>>
>>> On Thu, 28 Sep 2023 22:45:24 -0700
>>> Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
>>>
>>>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>>>
>>>>> You've asserted in the past that there's a logical reason behind
>>>>> using the term "literal" for these two constructs and not for
>>>>> others, such as integer constants. I'm not particularly interested
>>>>> in debating that point again, but I see no support in the standard
>>>>> for that assertion. (The standard also uses the word "literal" as
>>>>> an adjective; see for example N1570 6.1p1 where it refers to
>>>>> terminals in the grammar.)
>>>>
>>>> I don't have my previous posting in front of me,
>>>
>>> <86r0o887op.fsf@linuxsc.com> and <86fs4k6pgq.fsf@linuxsc.com> .
>>
>> I know references like that are helpful for some people,
>> however they are not for me.[*] Thank you though for
>> trying to help.
>
>I can't help wondering what you mean. You seem to use GNUS, as I do,
>and I find such reference the most useful of all as just one click and
>I'm, reading the referenced article in the same window.
>
>> [*] And I have no desire to change that, at least not any time
>> soon.

Be that as it may, here is (one of) the article(s) to which we are all
referring:

From tr.17687@z991.linuxsc.com Fri Sep 29 11:14:57 MDT 2023
Article: 1091108 of comp.lang.c
Path: nnrp.xmission!xmission!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups: comp.lang.c
Subject: Re: you think rust may outthrone c?
Date: Sat, 12 Aug 2023 10:57:42 -0700
Message-ID: <86r0o887op.fsf@linuxsc.com>

....
The word literal, used as a noun when describing programming
languages, came into vogue sometime after it became common to
specify language syntax by using a formal grammar (usually
expressed in some variation of Backus-Naur Form); roughly the
1970s timeframe. A typical usage would be for "literal" to be
synonymous with "terminal symbol", or perhaps with just a subset
of terminal symbols, as used in the rules of grammar. In some
cases the words "constant" and "literal" were used more or less
interchangeably.

A good decade earlier, however, the word literal was used in a
somewhat different programming language context, not as part of
describing a language but as an element of the language. The
assembly language for IBM System/360 had constants, both ordinary
numeric and character constants, and symbolic constants (defined
with EQU). Constants could be used as direct operands for some
instructions, depending on the particulars of the instruction and
for which operand, and represented values encoded directly in the
instruction. Distinct from constants there were also /literals/,
a distinct category of operand that produced the address of an
initialized anonymous region of memory. Here are two example
lines of assembly, to illustrate the difference:

OI VAL+2,X'F0'
C 3,=F'1000'

In the first line, there are two constants, 2 and X'F0'. These
tokens are numerical quantities that are used directly in the
generated instruction. (In the case of the constant 2 the value
is added to the address VAL, and it is the sum that is used to
produce the bytes of the instruction, but the key property is
that the value 2 participates locally, and not remotely.)

The second line has a constant 3 and a literal =F'1000'. Like in
the first line, the value 3 is used directly in the generated
instruction. The literal =F'1000' is not used directly. Instead,
the assembler keeps track of literals used in the program, and
uses them to initialize areas of memory elsewhere in the program.
A use of a literal, such as the =F'1000' here, results in the
address of the memory area reserved for the value of the literal.
(There are some further details about literals, such as literal
pools and the LTORG directive, that I won't explain because those
details are not important to the discussion.)

Note the parallels between how these terms are used in assembly
language and in C. Constants are used to generate code but appear
only implicitly; literals always occupy areas of memory (objects)
and use of a literal causes its address (lvalue) to be part of a
generated instruction. The distinction between constants and
literals is primarily a semantic distinction, not a syntactic one.

Besides being more historically faithful, having two different
terms provides a useful semantic distinction that would disappear
if the term "literal" were used for both concepts.

>> Given a choice between the level of confusion seen in the C++
>> standard and the level of confusion seen in the C standard ("integer
>> constant" and "integer constant expression" is confusing? really?)
>> I'm happy to be on the side of C's choice any day of the week and
>> twice on Sunday. Please cast my vote to continue using the terms
>> "constant" and "literal" as they are used in the C standard.
>
> I use those terms simply because that's how they're used in the C
> standard.

Obviously it's a good idea to use terminology in the C standard
when talking about the C language. My point though is that the
terminology used in the C standard is a better choice both
historically and semantically.

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

Re: Libraries using longjmp for error handling

<86h6ncgalz.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Fri, 29 Sep 2023 10:20:08 -0700
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <86h6ncgalz.fsf@linuxsc.com>
References: <65SQM.565977$9o89.411905@fx05.ams4> <wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk> <pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid> <20230928160237.9796f1896cb0be293bd24b76@gmail.moc> <87jzsae7jm.fsf@bsb.me.uk> <20230928183129.fb386b543c40cd56340ca40f@gmail.moc> <20230928093424.111@kylheku.com> <8634yxj3uh.fsf@linuxsc.com> <87a5t5sr2j.fsf@nosuchdomain.example.com> <86lecph6rv.fsf@linuxsc.com> <owGlRX9UheAv7IQ6v@bongo-ra.co> <20230929181110.db35a227b46ec7e463f3801e@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="13636bbb038e3a1f79d11dd50eec8409";
logging-data="410337"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+q0SpJYxXa+KucspoFm088GDyU3Kr13Nk="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:s4aq9yCrXY/KIdpMEfKV29glfUk=
sha1:h25BRg65BFT9qJAzxUU2auOxHoY=
 by: Tim Rentsch - Fri, 29 Sep 2023 17:20 UTC

Anton Shepelev <anton.txt@gmail.moc> writes:

> Spiros Bousbouras to Tim Rentsch:
>
>>> I don't have my previous posting in front of me,
>>
>> <86r0o887op.fsf@linuxsc.com> and
>> <86fs4k6pgq.fsf@linuxsc.com> .
>
> What fine Message-Id:s!

Thank you. I can assure you that I played no conscious role
in selecting them. :)

> Does FSF stand for the Free Software Fondation?

Certainly it might. The colo server here runs ubuntu linux.

> Tim might appreciate working URLs to archived messages:
>
> http://al.howardknight.net/?ID=169556843200
> http://al.howardknight.net/?ID=169556849300

There are cases where I might. In this particular case I
felt confident enough simply relying on my memory, even
though it seems to be more and more in need of ECC as years
go by.

Re: Libraries using longjmp for error handling

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

  copy mid

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

  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: Libraries using longjmp for error handling
Date: Fri, 29 Sep 2023 11:30:40 -0700
Organization: None to speak of
Lines: 32
Message-ID: <87y1gorfvz.fsf@nosuchdomain.example.com>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<20230928160237.9796f1896cb0be293bd24b76@gmail.moc>
<87jzsae7jm.fsf@bsb.me.uk>
<20230928183129.fb386b543c40cd56340ca40f@gmail.moc>
<20230928093424.111@kylheku.com> <8634yxj3uh.fsf@linuxsc.com>
<87a5t5sr2j.fsf@nosuchdomain.example.com> <86lecph6rv.fsf@linuxsc.com>
<owGlRX9UheAv7IQ6v@bongo-ra.co>
<20230929181110.db35a227b46ec7e463f3801e@gmail.moc>
<86h6ncgalz.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="1fa6e41457ad27ef0d3a035f975e01f4";
logging-data="434818"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/tpdQ6W+yCuQ4c4HfXbcVH"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:RPW515QsGjNatiZyBJWuTB0pc08=
sha1:f45qZsY0iGHkh7xeLwevLrTODVE=
 by: Keith Thompson - Fri, 29 Sep 2023 18:30 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> Anton Shepelev <anton.txt@gmail.moc> writes:
>> Spiros Bousbouras to Tim Rentsch:
>>>> I don't have my previous posting in front of me,
>>>
>>> <86r0o887op.fsf@linuxsc.com> and
>>> <86fs4k6pgq.fsf@linuxsc.com> .
>>
>> What fine Message-Id:s!
>
> Thank you. I can assure you that I played no conscious role
> in selecting them. :)
>
>> Does FSF stand for the Free Software Fondation?
>
> Certainly it might. The colo server here runs ubuntu linux.

Not relevant. Gnus includes ".fsf" in the Message-Ids it generates.

It also includes the domain name from which you post. (linuxsc.com in
your case). I prefer not to include that information, so I have

(setq message-user-fqdn "nosuchdomain.example.com")

in my .emacs file.

[...]

--
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: Libraries using longjmp for error handling

<20230929111638.131@kylheku.com>

  copy mid

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

  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: Libraries using longjmp for error handling
Date: Fri, 29 Sep 2023 18:31:08 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <20230929111638.131@kylheku.com>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<20230928160237.9796f1896cb0be293bd24b76@gmail.moc>
<87jzsae7jm.fsf@bsb.me.uk>
<20230928183129.fb386b543c40cd56340ca40f@gmail.moc>
<20230928093424.111@kylheku.com> <8634yxj3uh.fsf@linuxsc.com>
<87a5t5sr2j.fsf@nosuchdomain.example.com> <86lecph6rv.fsf@linuxsc.com>
Injection-Date: Fri, 29 Sep 2023 18:31:08 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3e2464a16a598f67870a96179f3b3745";
logging-data="436886"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+JDJ1zYQDuhO6qFezNLnoSgtfVFaeDQIQ="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:27+9An9R8eCceOB/5Tv4rYhUfkQ=
 by: Kaz Kylheku - Fri, 29 Sep 2023 18:31 UTC

On 2023-09-29, Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
> I'm not saying anything about whether something is a "true
> literal", whatever that might be. What I am saying is that
> a compound literal is a literal in the same sense that the
> term was originally used, and that sense is consistent with
> both string literals and compound literals (but not with
> constants such as integer constants or floating constants).

Integer constants are not literals according some supposedly widely
understood sixty-year-old meaning of "literal"?

Are you okay?

C neglecting to use "literal" for integer constants is just a mistake.
It's okay to recognize that.

FWIW, the latest C draft does now have "compound literal constant" which
is defined using constexpr storage class. If you make one of these
beasties with int type, and give it a value like 42, then you
finally have a literal constant in C, of type int, with value 42.
That token 42 is, sadly, not called a literal.

--
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: Libraries using longjmp for error handling

<20230929114657.513@kylheku.com>

  copy mid

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

  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: Libraries using longjmp for error handling
Date: Fri, 29 Sep 2023 18:53:38 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <20230929114657.513@kylheku.com>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<20230928160237.9796f1896cb0be293bd24b76@gmail.moc>
<87jzsae7jm.fsf@bsb.me.uk>
<20230928183129.fb386b543c40cd56340ca40f@gmail.moc>
<20230928093424.111@kylheku.com> <8634yxj3uh.fsf@linuxsc.com>
<87a5t5sr2j.fsf@nosuchdomain.example.com> <86lecph6rv.fsf@linuxsc.com>
<owGlRX9UheAv7IQ6v@bongo-ra.co> <86wmw9f21z.fsf@linuxsc.com>
Injection-Date: Fri, 29 Sep 2023 18:53:38 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3e2464a16a598f67870a96179f3b3745";
logging-data="439550"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18BAe0A2yZ0PkEsDj52xe7aHHbfhxJ0CuM="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:5njUwrELcgPBCbquheK+8bPk5Y4=
 by: Kaz Kylheku - Fri, 29 Sep 2023 18:53 UTC

On 2023-09-29, Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
> Spiros Bousbouras <spibou@gmail.com> writes:
>
>> On Thu, 28 Sep 2023 22:45:24 -0700
>> Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
>>
>>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>>
>>>> You've asserted in the past that there's a logical reason behind
>>>> using the term "literal" for these two constructs and not for
>>>> others, such as integer constants. I'm not particularly interested
>>>> in debating that point again, but I see no support in the standard
>>>> for that assertion. (The standard also uses the word "literal" as
>>>> an adjective; see for example N1570 6.1p1 where it refers to
>>>> terminals in the grammar.)
>>>
>>> I don't have my previous posting in front of me,
>>
>> <86r0o887op.fsf@linuxsc.com> and <86fs4k6pgq.fsf@linuxsc.com> .
>
> I know references like that are helpful for some people,
> however they are not for me.[*] Thank you though for
> trying to help.
>
> [*] And I have no desire to change that, at least not any time
> soon.

I see you are using Gnus, the Emacs-based newsreader, connected
to the same NTTP server as what I'm using.

The articles referenced above are still held by the server.

In the SLRN newsreader that I'm using, there is a simple ESC-l
command that prompts for the message ID. It finds the article
and brings it into the article display. I was able to find
the articles this way.

It would be astonishing if the equivalent trick couldn't be done with
Gnus.

I quit Emacs in 1994, and have never used Gnus, but the documentation
says:

Article Keymap
--------------

[ ... ]

C-c ^
If point is in the neighborhood of a Message-Id and you press r,
Gnus will try to get that article from the server
(gnus-article-refer-article).

--
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: Libraries using longjmp for error handling

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

  copy mid

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

  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: Libraries using longjmp for error handling
Date: Fri, 29 Sep 2023 21:02:11 +0100
Organization: A noiseless patient Spider
Lines: 146
Message-ID: <8734ywbvek.fsf@bsb.me.uk>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<AE3RM.402236$kCld.195109@fx08.ams4> <871qejf62x.fsf@bsb.me.uk>
<86y1gphiur.fsf@linuxsc.com> <877co9d8m2.fsf@bsb.me.uk>
<86bkdlghqr.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="4dfdf850a714e5d3717da460fbf945f6";
logging-data="468862"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+6zS9VTAjcWhw/xDcDLhOm9cY2tx2OjoQ="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:POet456RLXXrr+e+KIdyFufBHR4=
sha1:U9E6y1nq8t0f0SJUX5aqEEq4Qlk=
X-BSB-Auth: 1.4ac09398f301a7a1951d.20230929210211BST.8734ywbvek.fsf@bsb.me.uk
 by: Ben Bacarisse - Fri, 29 Sep 2023 20:02 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:

> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>
>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>
>>> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>>>
>
> [..how should errors be handled..]
>
>>>> If it's done well, the result is not even "error handling" -- it's
>>>> just what the function returns. For example, a lookup in a table
>>>> of integers in Haskell returns a type that is, in effect "maybe an
>>>> integer" The return will be either "Nothing" or something like
>>>> "Just 42".
>>>
>>> In languages that support it this approach is a good way to deal
>>> with cases like this, I agree. But to me it falls in a different
>>> category than error handling. An error condition is something
>>> like an allocation (eg malloc()) failure, or a broken pipe. Not
>>> finding something in a table means whoever was responsible for
>>> adding things to the table didn't add it - in other words it was
>>> entirely a consequence of events that are under the program's
>>> control. The issue is how to deal with an unpredictable, and
>>> usually very rare, event that is not something the program has
>>> control over. Typically these kinds of situations need a
>>> different sort of mechanism than loading up the return value
>>> of every function call.
>>
>> I agree that table lookup is not a compelling example, but I don't
>> agree that anything different is needed. I intended the idea to
>> be generalised to have return values used for all error
>> conditions. There may be situations where something different is
>> /better/, but I remain sceptical of even this claim. Note I am
>> not talking about situations where asynchronous errors need to be
>> reported.
>>
>> C uses null pointers for this all the time. Returning a null
>> pointer is just a way to signal an error through the return value.
>> In a language like C without null pointers I would want malloc to
>> return a 'Maybe' type. And for when more information is wanted
>> (like your example of a broken pipe) the type returned from write
>> should be a number of bytes or an error value of some sort.
>>
>> Obviously it's hard to recommend this in C since the language
>> can't really express the patterns needed to make it convenient,
>> but I think we are talking more generally here.
>
> I acknowledge your statement about not considering asynchronous
> errors. My own comments are likewise.
>
> I agree that all unusual result circumstances (which might be
> labeled "error conditions", without meaning to prejudice the term)
> can be handled locally via either compound return values or multiple
> return values (eg, by using pointer parameters), or a combination of
> the two. In languages that provide good support for compound return
> values, which I would say C does not, probably a single return value
> (which is perhaps a compound value) always suffices, but I haven't
> thought very carefully about that. But I think we are in general
> agreement that it's always possible to handle error conditions via
> local return values.
>
> Where we might not agree is whether using direct return values is
> always a good choice. In my view, sometimes it is, sometimes it
> isn't - it depends on the particular situation. That is definitely
> the case for C, but I think also for other programming languages
> that have better support for multiple return values or compound
> return values, or both. And certainly if needing other mechanisms
> is true for languages in general then it we would expect it is true
> for C.
>
>> How would you prefer these sorts of thing to be signalled?
>
> Let me give just one example.
>
> kI wrote some code not long ago to add a value to a set of values,
> where the set is represented using a recursive binary tree structure
> (like red-black trees, but a little different). Usually we may
> expect that a request to add a value would offer a value not already
> included in the set, but certainly it can happen that there is a
> call to add a value that is already included, in which case the top
> level return value should be the original tree structure.
>
> I thought it would be easier to write a simple recursive routine
> that assumes the to-be-added value is not yet included in the set,
> and if that assumption is violated raise an exception that is caught
> at the outermost level and simply returns the original argument tree
> value. Certainly the code could have been written to handle the
> already-present situation at each level of the recursion, but it was
> much easier and much cleaner to handle it by raising an exception.

This is one of those cases where I just have to take your word for it,
(and I am happy to do that).

> That example doesn't translate to C in any obvious way, because C
> code to add items to a set would very likely be written rather
> differently. I think it's harder to make use of non-local returns
> in C than in many other languages, because C requires more thought
> and discipline to set that up. At the same time, when I look at C
> code that tries to handle all exceptional conditions locally, I
> can't help but think the code would be simplified overall if code
> for dealing with exceptional conditions could be removed in the code
> generally and instead used a different mechanism, in fewer places,
> and perhaps similar to raising an exception, to handle such cases.

You may be right, but I don't like exceptions. More specifically, I
don't like exceptions that are not handled internally in some API or
other (so your tree example sounds like a sane use for them), but I
worry about their wider use. You either have to wrap every call in a
"try" (in which case why not use the multiple value return method) or
the reasoning about correctness starts to get more and more
complicated.

>> BTW, have you come across Icon?
>
> I have, and it's a fascinating language.
>
>> It takes an intriguing approach
>> where every operation succeeds or fails as well as having a value.
>
> I have heard Icon characterized as saying "it tries to succeed",
> and I think that's a fair description. The idea of integrating
> a backtracking engine into the language semantics deserves more
> attention than I think it has been given, which is unfortunate.
>
>> This idea is heavily built upon to produce a very comfortable
>> scripting language.
>
> My experience with Icon is purely academic, which is to say I have
> read about it but never used it. I have more experience with
> Prolog, which is similar in some ways (notably backtracking) but of
> course very different in other ways.
>
> I'm intrigued by your comment that Icon makes a good scripting
> language. Maybe I don't understand what you think makes a good
> scripting language, or even what "scripting language" means.
> That subject is not topical in comp.lang.c, but I also peruse
> comp.lang.misc and comp.programming if you wouldn't mind
> continuing there. Also you are welcome to send me an email
> at this address if you would rather do that.

It was a careless remark with no significant meaning.

--
Ben.

Re: Libraries using longjmp for error handling

<20230929235846.a0883e001c83bbe718f5ab90@gmail.moc>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton....@gmail.moc (Anton Shepelev)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Fri, 29 Sep 2023 23:58:46 +0300
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <20230929235846.a0883e001c83bbe718f5ab90@gmail.moc>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<AE3RM.402236$kCld.195109@fx08.ams4>
<871qejf62x.fsf@bsb.me.uk>
<86y1gphiur.fsf@linuxsc.com>
<877co9d8m2.fsf@bsb.me.uk>
<86bkdlghqr.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="3bdc4bdf1da34ce85a13197decb6d776";
logging-data="485863"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19bPa73MSQz482/7EGn4b+C82/k+E2Aba4="
Cancel-Lock: sha1:OPNG6ezpiU6TbrrSG9sUlbEDXTg=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
 by: Anton Shepelev - Fri, 29 Sep 2023 20:58 UTC

Tim Rentsch:

> kI wrote some code not long ago to add a value to a set of
> values, where the set is represented using a recursive
> binary tree structure (like red-black trees, but a little
> different). Usually we may expect that a request to add a
> value would offer a value not already included in the set,
> but certainly it can happen that there is a call to add a
> value that is already included, in which case the top
> level return value should be the original tree structure.

Returning an error flag (or code) all the way up the call
stack may seem (and be) slow and cumbersome. If that case,
one can rewrite the recursive function iteratively, with an
explicit stack. I, however, think that an extra `if' in the
recursive function is so much less fuss

--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments

Re: Libraries using longjmp for error handling

<86cyy0fee5.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Fri, 29 Sep 2023 21:56:02 -0700
Organization: A noiseless patient Spider
Lines: 92
Message-ID: <86cyy0fee5.fsf@linuxsc.com>
References: <65SQM.565977$9o89.411905@fx05.ams4> <wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk> <pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid> <AE3RM.402236$kCld.195109@fx08.ams4> <871qejf62x.fsf@bsb.me.uk> <86y1gphiur.fsf@linuxsc.com> <877co9d8m2.fsf@bsb.me.uk> <86bkdlghqr.fsf@linuxsc.com> <8734ywbvek.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="a99bceb92abacf1e025e751f28ca3812";
logging-data="761663"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/7hnnvPa4YK5hJq9ErRuV4fCdwfF1ZV2w="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:Cb6PFJJBJkfZBVFrXasslttpgNU=
sha1:LYcUGZJB1MV0Q9McMVxhDIkUEIQ=
 by: Tim Rentsch - Sat, 30 Sep 2023 04:56 UTC

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

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>
>> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>>
>> [..how should errors be handled..]
>>
>>> How would you prefer these sorts of thing to be signalled?
>>
>> Let me give just one example.
>>
>> I wrote some code not long ago to add a value to a set of values,
>> where the set is represented using a recursive binary tree structure
>> (like red-black trees, but a little different). Usually we may
>> expect that a request to add a value would offer a value not already
>> included in the set, but certainly it can happen that there is a
>> call to add a value that is already included, in which case the top
>> level return value should be the original tree structure.
>>
>> I thought it would be easier to write a simple recursive routine
>> that assumes the to-be-added value is not yet included in the set,
>> and if that assumption is violated raise an exception that is caught
>> at the outermost level and simply returns the original argument tree
>> value. Certainly the code could have been written to handle the
>> already-present situation at each level of the recursion, but it was
>> much easier and much cleaner to handle it by raising an exception.
>
> This is one of those cases where I just have to take your word for it,
> (and I am happy to do that).

Responding here to just this one part.

Here is a simpler version of the code, for an ordinary
binary tree, and without any rebalancing:

module TreeSet = struct
type 'a treeset = Empty | Node of 'a treeset * 'a * 'a treeset
exception Present

let add tree element =
let rec add t e =
match t with
| Empty -> Node( Empty, e, Empty )
| Node( a, v, b ) ->
if e < v then Node( add a e, v, b ) else
if e > v then Node( a, v, add b e ) else
raise Present
in
try add tree element with Present -> tree

end

Transliterating that into C, the central functions might look like
this (I have left out the type definition and the constructor
function used to build a new node value):

static Tree add( jmp_buf, Tree, double );
static Tree raise_present( jmp_buf );
static Tree new_node( Tree, double, Tree );

Tree
add_element( Tree tree, double new_element ){
jmp_buf jb;
if( setjmp( jb ) ) return tree;

return add( jb, tree, new_element );
}

Tree
add( jmp_buf jb, Tree t, double d ){
return
! t ? new_node( 0, d, 0 )
: d < t->v ? new_node( add( jb, t->a, d ), t->v, t->b )
: d > t->v ? new_node( t->a, t->v, add( jb, t->b, d ) )
: /*********/ raise_present( jb );
}

Tree
raise_present( jmp_buf jb ){
longjmp( jb, 1 );
}

Of course it's unlikely that sets would be implemented this way
in C, but that's not the point; the point is that exceptions
can result in code that is cleaner and easier to understand
than an alternate approach where return values would have to
be checked at every level.

(Incidentally, I want to acknowlege you comment about taking my
word for the result. I still thought it would be good to give
a concrete example, even if it is a very simplified one.)


devel / comp.lang.c / Re: Libraries using longjmp for error handling

Pages:123
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor