Article View: comp.lang.c
Article #1313Re: .5 against 0.5f
From: Kaz Kylheku
Date: Tue, 03 Nov 2026 18:25
Date: Tue, 03 Nov 2026 18:25
60 lines
3975 bytes
3975 bytes
On 2026-11-03, Dan Cross <cross@spitfire.i.gajendra.net> wrote:
> In article <11c8dls$2chr0$1@dont-email.me>,
> James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
>>On 2026-10-29 17:55, Janis Papanagnou wrote:
>>> On 2026-10-29 20:49, Dan Cross wrote:
>>>> [...]
>>>>
>>>> But again, the whole premise (that a programmer familiar with C
>>>> would ever think that `return` is a function) is silly.
>>
>>Agreed. The misconception is far more common among those
>>who aren't very familiar with C.
>
> It is not common at all.
You have to get to a certain advanced level of education in computer
science before you start believing that returning is another function
calls.
But it's there. The returning control flow can be modeled by
continuations.
We can eliminate returns from a program by passing a context
argument to each function: the return continuation. The places
where the function returns become tail calls to the continuation.
The transformation of a program to continuation passing style ("CPS
transformation") can be done by a compiler, allowing a program in a
language in which ordinary function returning appears to work under the
hood by returns achieved by a function call.
How it works is that all the code that would take place in the
caller after a function returns is bundled into a lambda body,
and the lambda is passed as the continuation argument.
(This is now actually very familiar to youngsters who work in web front
end and know about "async" functions. In that paradigm, a kind of
continuation system appears whereby the computation we'd like to do from
now on, but only after some event is received, is farmed out to a
lambda.)
Famously, (to tie this back to C somehow), Chicken Scheme implements
continuation over the native stack in a particular way. Chicken Scheme
code is translated to C code, and that C code never returns from its
functions. It always passes a lambda to the callee. Lambdas capture
their context on the stack. Because nothing ever returns, pointers and
other objects on the stack nicely persist: local variables don't die
after a function returns because it's compiled to a C function that
returns by calling a continuation. When the stack hits a certain limit,
it is rewound back to the top. At that time, all the objects in the
stack that are still live are identified and moved to the heap. I think,
even character strings in their entirety (the actual array) are
bump-allocated on the stack, and so have to be memmoved to the heap when
the stack rewinds, so the stack acts as a nursery for new objects.
--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
Technical Details
Message-ID:
<20261103101134.247@kylheku.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<11bpvs7$1e6kc$2@dont-email.me> <11c07vf$lhk$1@reader2.panix.com> <11c0fcj$2t865$2@dont-email.me> <11c8dls$2chr0$1@dont-email.me> <11cc6vo$6eh$1@reader2.panix.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Kaz Kylheku <046-301-5902@kylheku.com> Newsgroups: comp.lang.c Subject: Re: .5 against 0.5f Date: Tue, 3 Nov 2026 18:25:53 -0000 (UTC) Organization: A noiseless patient Spider Lines: 60 Message-ID: <20261103101134.247@kylheku.com> References: <11bpvs7$1e6kc$2@dont-email.me> <11c07vf$lhk$1@reader2.panix.com> <11c0fcj$2t865$2@dont-email.me> <11c8dls$2chr0$1@dont-email.me> <11cc6vo$6eh$1@reader2.panix.com> Injection-Date: Tue, 03 Nov 2026 18:25:54 +0000 (UTC) Injection-Info: dont-email.me; logging-data="37141"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/eyU7I+BUt4ZSdgGKMZYhEG3N/aOp9+tQ="; posting-host="ea46c3c53b7b33655f62f2e1d58addc9" User-Agent: slrn/pre1.0.4-9 (Linux) Cancel-Lock: sha1:S0csvbC7z/ZejuXT5+dq5dQl61s= sha256:+iKbIa9xICV3XGoeZdtIL9qWBE8ho+CHGev3P4wdqEY= sha1:K2gue0x3xSwwTZL6uHdPLus9o6k= sha256:n+tPUMKehZRgBr388gB2EfQ0rPiGFF+YZoJNmsH2ySE=