Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: Does this program have the specified behavior?
Date: Fri, 10 Dec 2021 01:40:33 -0800
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <86y24s7q7i.fsf@linuxsc.com>
References: <2ce7a201-45d4-49aa-a512-2ca01a4fbd36n@googlegroups.com> <3e59b2b4-88f9-4bd1-8cf7-eb7baee8c214n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="94ee63d76223a75d29f96ac519efdd3f"; logging-data="13838"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+rRsrdo9uaOcV+PQCP5ldtfC1AHBgyNl0="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:wndgos97MjXJUvXxnxEvbm/arlc= sha1:Ch9F06xTo/+ejwovMlZ2exfvPl8=
Xref: csiph.com comp.lang.c:163759
Mark Bluemel writes:
> On Wednesday, 17 November 2021 at 05:13:08 UTC, Chris M. Thomasson wrote:
>
>> On 11/16/2021 8:46 PM, olcott wrote:
>>
>>> #include
>>> #include
>>> typedef int (*ptr)();
>>>
>>> int H(ptr x, ptr y)
>>> {
>>> x(y); // direct execution of P(P)
>>> return 1;
>>> }
>>>
>>> int P(ptr x)
>>> {
>>> H(x, x);
>>> return 1;
>>> }
>>>
>>> int main(void)
>>> {
>>> H(P, P);
>>> }
>>
>> Stack overflow...
>
> Surely a compiler can optimise this to remove the recursion, and
> for that matter, remove any functionality at all, as the code has
> no observable behaviour, as far as I can see (I'd be happy to be
> corrected on this!).
A program that simply does a 'return 0;' from main() does have
observable behavior: it modifies no files (and doesn't perform
any volatile accesses or do any I/O to interactive devices). The
empty set is still a set.
By contrast, a program that sits and does nothing and simply runs
forever does /not/ have observable behavior. The reason is
simple: the predicate condition for what happens with files is
evaluated only at program termination. No termination means no
way to assess observable behavior.
The question of whether the C standard allows (or intends to
allow) the program transformation you describe is a thorny
problem, and not one I'm planning on researching further. But
considering just "observable behavior" in the two cases, ISTM
that the two programs clearly are not identical, because one
does have observable behavior and the other one does not.