Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #163431 > unrolled thread
| Started by | olcott <NoOne@NoWhere.com> |
|---|---|
| First post | 2021-11-16 21:33 -0600 |
| Last post | 2021-11-17 22:00 +0000 |
| Articles | 20 — 10 participants |
Back to article view | Back to comp.lang.c
Do this program have the specified behavior? olcott <NoOne@NoWhere.com> - 2021-11-16 21:33 -0600
Does this program have the specified behavior? olcott <NoOne@NoWhere.com> - 2021-11-16 22:46 -0600
Re: Does this program have the specified behavior? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-11-16 21:12 -0800
Re: Does this program have the specified behavior? Mark Bluemel <mark.bluemel@gmail.com> - 2021-11-17 00:28 -0800
Re: Does this program have the specified behavior? olcott <NoOne@NoWhere.com> - 2021-11-17 08:33 -0600
Re: Does this program have the specified behavior? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-12-10 01:40 -0800
Re: Does this program have the specified behavior? Richard Damon <Richard@Damon-Family.org> - 2021-12-10 07:56 -0500
Re: Does this program have the specified behavior? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-12-11 09:40 -0800
Re: Does this program have the specified behavior? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-12-11 16:37 -0800
Re: Does this program have the specified behavior? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-12-12 09:29 -0800
Re: Does this program have the specified behavior? antispam@math.uni.wroc.pl - 2021-12-11 19:38 +0000
Re: Does this program have the specified behavior? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-12-11 16:45 -0800
Re: Does this program have the specified behavior? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-12-12 08:53 -0800
Re: Does this program have the specified behavior? Richard Damon <Richard@Damon-Family.org> - 2021-11-17 06:53 -0500
Re: Does this program have the specified behavior? olcott <NoOne@NoWhere.com> - 2021-11-17 08:49 -0600
Re: Does this program have the specified behavior? Juha Nieminen <nospam@thanks.invalid> - 2021-11-18 06:32 +0000
Re: Does this program have the specified behavior? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-11-18 11:15 +0000
Re: Does this program have the specified behavior? olcott <NoOne@NoWhere.com> - 2021-11-18 08:59 -0600
Re: Does this program have the specified behavior? olcott <NoOne@NoWhere.com> - 2021-11-18 08:58 -0600
Re: Does this program have the specified behavior? Anurag Ranjan <anuragranjan630@gmail.com> - 2021-11-17 22:00 +0000
| From | olcott <NoOne@NoWhere.com> |
|---|---|
| Date | 2021-11-16 21:33 -0600 |
| Subject | Do this program have the specified behavior? |
| Message-ID | <TeidndjwvpeU5Qn8nZ2dnUU7-QmdnZ2d@giganews.com> |
#include <stdint.h>
typedef void (*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);
}
For every H that simulates or executes its input and aborts or does not
abort its input P never reaches its last instruction.
--
Copyright 2021 Pete Olcott
Talent hits a target no one else can hit;
Genius hits a target no one else can see.
Arthur Schopenhauer
[toc] | [next] | [standalone]
| From | olcott <NoOne@NoWhere.com> |
|---|---|
| Date | 2021-11-16 22:46 -0600 |
| Subject | Does this program have the specified behavior? |
| Message-ID | <L6KdnUDjcci1FAn8nZ2dnUU7-V_NnZ2d@giganews.com> |
| In reply to | #163431 |
On 11/16/2021 10:10 PM, wij wrote:
> On Wednesday, 17 November 2021 at 11:33:49 UTC+8, olcott wrote:
#include <stdint.h>
#include <stdio.h>
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);
}
For every H that simulates or executes its input and aborts or does not
abort its input P never reaches its last instruction.
> I would guess yes, it is specified: BAD, illegal program
It must be compiled as C and the typedef was incorrect.
I can't find a way to specify the "C" calling convention for g++
--
Copyright 2021 Pete Olcott
Talent hits a target no one else can hit;
Genius hits a target no one else can see.
Arthur Schopenhauer
[toc] | [prev] | [next] | [standalone]
| From | "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> |
|---|---|
| Date | 2021-11-16 21:12 -0800 |
| Subject | Re: Does this program have the specified behavior? |
| Message-ID | <sn230n$q4t$1@dont-email.me> |
| In reply to | #163432 |
On 11/16/2021 8:46 PM, olcott wrote:
> #include <stdint.h>
> #include <stdio.h>
> 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...
[toc] | [prev] | [next] | [standalone]
| From | Mark Bluemel <mark.bluemel@gmail.com> |
|---|---|
| Date | 2021-11-17 00:28 -0800 |
| Subject | Re: Does this program have the specified behavior? |
| Message-ID | <3e59b2b4-88f9-4bd1-8cf7-eb7baee8c214n@googlegroups.com> |
| In reply to | #163433 |
On Wednesday, 17 November 2021 at 05:13:08 UTC, Chris M. Thomasson wrote:
> On 11/16/2021 8:46 PM, olcott wrote:
> > #include <stdint.h>
> > #include <stdio.h>
> > 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!).
$DIETY only knows what olcott was trying to show with this code.
[toc] | [prev] | [next] | [standalone]
| From | olcott <NoOne@NoWhere.com> |
|---|---|
| Date | 2021-11-17 08:33 -0600 |
| Subject | Re: Does this program have the specified behavior? |
| Message-ID | <Fb6dnZbpVugnjwj8nZ2dnUU7-RudnZ2d@giganews.com> |
| In reply to | #163434 |
On 11/17/2021 2:28 AM, Mark Bluemel wrote:
> On Wednesday, 17 November 2021 at 05:13:08 UTC, Chris M. Thomasson wrote:
>> On 11/16/2021 8:46 PM, olcott wrote:
>>> #include <stdint.h>
>>> #include <stdio.h>
>>> 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!).
>
This is the question:
For every H that simulates or executes its input and aborts or does not
abort its input does any P ever reach its last instruction?
> $DIETY only knows what olcott was trying to show with this code.
>
--
Copyright 2021 Pete Olcott
Talent hits a target no one else can hit;
Genius hits a target no one else can see.
Arthur Schopenhauer
[toc] | [prev] | [next] | [standalone]
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| Date | 2021-12-10 01:40 -0800 |
| Subject | Re: Does this program have the specified behavior? |
| Message-ID | <86y24s7q7i.fsf@linuxsc.com> |
| In reply to | #163434 |
Mark Bluemel <mark.bluemel@gmail.com> 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 <stdint.h>
>>> #include <stdio.h>
>>> 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.
[toc] | [prev] | [next] | [standalone]
| From | Richard Damon <Richard@Damon-Family.org> |
|---|---|
| Date | 2021-12-10 07:56 -0500 |
| Subject | Re: Does this program have the specified behavior? |
| Message-ID | <G7IsJ.152140$831.93@fx40.iad> |
| In reply to | #163759 |
On 12/10/21 4:40 AM, Tim Rentsch wrote:
> Mark Bluemel <mark.bluemel@gmail.com> 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 <stdint.h>
>>>> #include <stdio.h>
>>>> 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.
>
I think the key point is that the infinite recursion means the program
exceeds the environment bounds for defined operation and thus the
behavior of the program has become officially 'Undefined Behavior'. Once
the compiler can see that this will happen, it is freed of all restrictions.
Any observable behavior that would happen before the program enters
Undefined Behavior needs to happen, but there is none, so the compiler,
if it is smart enough to recognize the behavior, is totally free to do
what ever it wants with the program.
[toc] | [prev] | [next] | [standalone]
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| Date | 2021-12-11 09:40 -0800 |
| Subject | Re: Does this program have the specified behavior? |
| Message-ID | <86czm36nwv.fsf@linuxsc.com> |
| In reply to | #163766 |
Richard Damon <Richard@Damon-Family.org> writes:
> On 12/10/21 4:40 AM, Tim Rentsch wrote:
>
>> Mark Bluemel <mark.bluemel@gmail.com> 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 <stdint.h>
>>>>> #include <stdio.h>
>>>>> 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.
>
> I think the key point is that the infinite recursion means the
> program exceeds the environment bounds for defined operation and
> thus the behavior of the program has become officially 'Undefined
> Behavior'. [...]
This conclusion isn't right. First, the C standard doesn't
mention any such environmental limit. Second, even if it did,
exceeding an environmental limit doesn't make defined behavior
turn into undefined behavior. Consider the following program:
int
main( void ){
int x;
{{{ .. one billion open braces... {{{
x = 0;
}}} .. one billion close braces.. }}}
return x;
}
An implementation is free to reject this program, but if the
program is accepted it has well-defined semantics, which is
to say its behavior is defined, not undefined. And that is
true regardless of what environmental limits the implementation
may have.
In the context of the C standard, the word "behavior" refers to a
specification, not an action. In other words the "behavior" of
a program is what the program /should/ do, not necessarily what the
program /will/ do, if and when it is executed. A program that just
recurses infinitely has "defined behavior" in the sense that the
C standard uses the term.
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Date | 2021-12-11 16:37 -0800 |
| Subject | Re: Does this program have the specified behavior? |
| Message-ID | <87k0gaacay.fsf@nosuchdomain.example.com> |
| In reply to | #163789 |
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
[...]
> In the context of the C standard, the word "behavior" refers to a
> specification, not an action. In other words the "behavior" of
> a program is what the program /should/ do, not necessarily what the
> program /will/ do, if and when it is executed.
[...]
The standard's definition of "behavior" is "external appearance or
action".
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */
[toc] | [prev] | [next] | [standalone]
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| Date | 2021-12-12 09:29 -0800 |
| Subject | Re: Does this program have the specified behavior? |
| Message-ID | <86sfux68b2.fsf@linuxsc.com> |
| In reply to | #163797 |
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> [...]
>
>> In the context of the C standard, the word "behavior" refers to a
>> specification, not an action. In other words the "behavior" of
>> a program is what the program /should/ do, not necessarily what the
>> program /will/ do, if and when it is executed.
>
> [...]
>
> The standard's definition of "behavior" is "external appearance or
> action".
It is. Despite that, in how the C standard uses the term it refers
to a specification for what should happen, not what actually does
happen. A program like this
int
main( void ){
unsigned x = 1;
return x == 0;
}
has defined behavior, whether the program is ever run or not, or
even whether the program is ever compiled. Some text in the C
standard is guilty, to be sure, of some sloppy usage in this
regard, but in context it's clear that "behavior" means a
description or specification of an external appearance or
action, and not an actual appearance or action. For example,
if a program has "undefined behavior", an implementation is
free to do what it chooses. That's a specification of what
appearances or actions are allowed (namely, anything at all),
not a statement of what appearances or actions take place.
[toc] | [prev] | [next] | [standalone]
| From | antispam@math.uni.wroc.pl |
|---|---|
| Date | 2021-12-11 19:38 +0000 |
| Subject | Re: Does this program have the specified behavior? |
| Message-ID | <sp2uoe$q7f$1@z-news.wcss.wroc.pl> |
| In reply to | #163759 |
Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
> Mark Bluemel <mark.bluemel@gmail.com> 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 <stdint.h>
> >>> #include <stdio.h>
> >>> 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.
AFAICS currently there is accepted view among theorists that
changing non-terminating behavior into terminating behaviour
is valid program transformation. Concerning C standard
relevant part in N1570 seem to be 5.1.2.3 point 6. IIUC
if program does not terminate on abstract machine clause
about files at program termination is empty: it places no
obligation on implementation. It seems that also clause
about interactive streams places no obligation on
implementation when program performs no I/O. So it seems
that according to N1570 changing non-terminating program
into terminating one is allowed.
At practical level gcc seem to keep infinite loop with empty
body. I can imagine why gcc is doing that...
--
Waldek Hebisch
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Date | 2021-12-11 16:45 -0800 |
| Subject | Re: Does this program have the specified behavior? |
| Message-ID | <87fsqyabxn.fsf@nosuchdomain.example.com> |
| In reply to | #163792 |
antispam@math.uni.wroc.pl writes:
[...]
> AFAICS currently there is accepted view among theorists that
> changing non-terminating behavior into terminating behaviour
> is valid program transformation. Concerning C standard
> relevant part in N1570 seem to be 5.1.2.3 point 6. IIUC
> if program does not terminate on abstract machine clause
> about files at program termination is empty: it places no
> obligation on implementation. It seems that also clause
> about interactive streams places no obligation on
> implementation when program performs no I/O. So it seems
> that according to N1570 changing non-terminating program
> into terminating one is allowed.
>
> At practical level gcc seem to keep infinite loop with empty
> body. I can imagine why gcc is doing that...
N1570 6.8.5p6 is relevant:
An iteration statement whose controlling expression is not a
constant expression, that performs no input/output operations, does
not access volatile objects, and performs no synchronization or
atomic operations in its body, controlling expression, or (in the
case of a for statement) its expression-3, may be assumed by the
implementation to terminate.
with a footnote:
This is intended to allow compiler transformations such as removal
of empty loops even when termination cannot be proven.
This was added in C11.
Personally, I dislike it, partly because it's written in terms of what
the implementation may assume rather than the behavior of a program.
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */
[toc] | [prev] | [next] | [standalone]
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| Date | 2021-12-12 08:53 -0800 |
| Subject | Re: Does this program have the specified behavior? |
| Message-ID | <86wnk969zc.fsf@linuxsc.com> |
| In reply to | #163792 |
antispam@math.uni.wroc.pl writes:
> Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
>
>> Mark Bluemel <mark.bluemel@gmail.com> 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 <stdint.h>
>>>>> #include <stdio.h>
>>>>> 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.
>
> AFAICS currently there is accepted view among theorists that
> changing non-terminating behavior into terminating behaviour
> is valid program transformation.
The question here concerns only what the C standard does or does
not allow.
> Concerning C standard
> relevant part in N1570 seem to be 5.1.2.3 point 6. IIUC
> if program does not terminate on abstract machine clause
> about files at program termination is empty: it places no
> obligation on implementation.
Changing a program that does not have observable behavior into
one that does have observable behavior is obviously a significant
change.
> It seems that also clause
> about interactive streams places no obligation on
> implementation when program performs no I/O. So it seems
> that according to N1570 changing non-terminating program
> into terminating one is allowed.
A follow-up from Keith Thompson points out N1570 6.8.5p6, which
explicitly allows turning kinds of non-terminating programs into
terminating programs. Since the C standard identifies specific
cases where such a tranformation /is/ allowed, it is reasonable
to infer that they are /not/ allowed in other cases. "The
exception proves the rule, in cases not excepted."
[toc] | [prev] | [next] | [standalone]
| From | Richard Damon <Richard@Damon-Family.org> |
|---|---|
| Date | 2021-11-17 06:53 -0500 |
| Subject | Re: Does this program have the specified behavior? |
| Message-ID | <536lJ.49729$JZ3.33398@fx05.iad> |
| In reply to | #163432 |
On 11/16/21 11:46 PM, olcott wrote:
> On 11/16/2021 10:10 PM, wij wrote:
>> On Wednesday, 17 November 2021 at 11:33:49 UTC+8, olcott wrote:
>
> #include <stdint.h>
> #include <stdio.h>
> 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);
> }
>
> For every H that simulates or executes its input and aborts or does not
> abort its input P never reaches its last instruction.
>
>> I would guess yes, it is specified: BAD, illegal program
>
> It must be compiled as C and the typedef was incorrect.
> I can't find a way to specify the "C" calling convention for g++
>
Shows you don't understand C++.
Making it 'C' calling convention doesn't change the syntax for the call.
In C++, an empty parameter list specifies a void parameter list, while
in C it specifies tha mostly obsolete concept that this is a
non-prototype declaration that doesn't specify the parameters.
Ultimately the problem is that this runs into the issue that it is
impossible to express in C a function that takes or returns a pointer to
the same type as the function itself is, as that requires self
references in the type definition.
[toc] | [prev] | [next] | [standalone]
| From | olcott <NoOne@NoWhere.com> |
|---|---|
| Date | 2021-11-17 08:49 -0600 |
| Subject | Re: Does this program have the specified behavior? |
| Message-ID | <dtOdnfVlRJHziwj8nZ2dnUU7-QHNnZ2d@giganews.com> |
| In reply to | #163440 |
On 11/17/2021 5:53 AM, Richard Damon wrote:
> On 11/16/21 11:46 PM, olcott wrote:
>> On 11/16/2021 10:10 PM, wij wrote:
>>> On Wednesday, 17 November 2021 at 11:33:49 UTC+8, olcott wrote:
>>
>> #include <stdint.h>
>> #include <stdio.h>
>> 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);
>> }
>>
>> For every H that simulates or executes its input and aborts or does not
>> abort its input P never reaches its last instruction.
>>
>>> I would guess yes, it is specified: BAD, illegal program
>>
>> It must be compiled as C and the typedef was incorrect.
>> I can't find a way to specify the "C" calling convention for g++
>>
>
> Shows you don't understand C++.
>
> Making it 'C' calling convention doesn't change the syntax for the call.
>
> In C++, an empty parameter list specifies a void parameter list, while
> in C it specifies tha mostly obsolete concept that this is a
> non-prototype declaration that doesn't specify the parameters.
>
> Ultimately the problem is that this runs into the issue that it is
> impossible to express in C a function that takes or returns a pointer to
> the same type as the function itself is, as that requires self
> references in the type definition.
>
This code does compile and run correctly.
The only difference from Ben's code is that
void (*ptr)(); was changed to int (*ptr)();
In comp.lang.c On 11/11/2021 2:31 PM, Ben Bacarisse:
transformed my syntax into his syntax
--
Copyright 2021 Pete Olcott
Talent hits a target no one else can hit;
Genius hits a target no one else can see.
Arthur Schopenhauer
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-11-18 06:32 +0000 |
| Subject | Re: Does this program have the specified behavior? |
| Message-ID | <sn4s2o$tke$1@gioia.aioe.org> |
| In reply to | #163444 |
In comp.lang.c++ olcott <NoOne@nowhere.com> wrote:
>>> typedef int (*ptr)();
>>>
>>> int H(ptr x, ptr y)
>>> {
>>> x(y); // direct execution of P(P)
>>> return 1;
>>> }
>
> This code does compile and run correctly.
It might compile as C, but it shouldn't compile as C++, because it's trying
to call an int(*)() with a parameter, even though that function (that the
pointer is pointing to does not take any parameter.)
Perhaps if it were an int(*)(void*) and then you reinterpret-cast the
parameter in order to call it, then it would compile.
As for "runs correctly", I don't see how this "runs correctly". Unless you
mean an infinite recursion that does nothing "runs correctly".
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2021-11-18 11:15 +0000 |
| Subject | Re: Does this program have the specified behavior? |
| Message-ID | <874k89ogte.fsf@bsb.me.uk> |
| In reply to | #163461 |
Juha Nieminen <nospam@thanks.invalid> writes:
> In comp.lang.c++ olcott <NoOne@nowhere.com> wrote:
>>>> typedef int (*ptr)();
>>>>
>>>> int H(ptr x, ptr y)
>>>> {
>>>> x(y); // direct execution of P(P)
>>>> return 1;
>>>> }
>>
>> This code does compile and run correctly.
>
> It might compile as C, but it shouldn't compile as C++, because it's trying
> to call an int(*)() with a parameter, even though that function (that the
> pointer is pointing to does not take any parameter.)
Just as it must not compile in C++, this code must compile in C. The
meaning of empty ()s in a function declaration is different between the
two languages.
When I tidied up the code, I wrote C, not C++, because C has a more
suitable type available.
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | olcott <NoOne@NoWhere.com> |
|---|---|
| Date | 2021-11-18 08:59 -0600 |
| Subject | Re: Does this program have the specified behavior? |
| Message-ID | <6oudnUgQRd6o9wv8nZ2dnUU7-e2dnZ2d@giganews.com> |
| In reply to | #163465 |
On 11/18/2021 5:15 AM, Ben Bacarisse wrote:
> Juha Nieminen <nospam@thanks.invalid> writes:
>
>> In comp.lang.c++ olcott <NoOne@nowhere.com> wrote:
>>>>> typedef int (*ptr)();
>>>>>
>>>>> int H(ptr x, ptr y)
>>>>> {
>>>>> x(y); // direct execution of P(P)
>>>>> return 1;
>>>>> }
>>>
>>> This code does compile and run correctly.
>>
>> It might compile as C, but it shouldn't compile as C++, because it's trying
>> to call an int(*)() with a parameter, even though that function (that the
>> pointer is pointing to does not take any parameter.)
>
> Just as it must not compile in C++, this code must compile in C. The
> meaning of empty ()s in a function declaration is different between the
> two languages.
>
> When I tidied up the code, I wrote C, not C++, because C has a more
> suitable type available.
>
You did a really great job.
--
Copyright 2021 Pete Olcott
Talent hits a target no one else can hit;
Genius hits a target no one else can see.
Arthur Schopenhauer
[toc] | [prev] | [next] | [standalone]
| From | olcott <NoOne@NoWhere.com> |
|---|---|
| Date | 2021-11-18 08:58 -0600 |
| Subject | Re: Does this program have the specified behavior? |
| Message-ID | <6oudnUkQRd6U9wv8nZ2dnUU7-e2dnZ2d@giganews.com> |
| In reply to | #163461 |
On 11/18/2021 12:32 AM, Juha Nieminen wrote:
> In comp.lang.c++ olcott <NoOne@nowhere.com> wrote:
>>>> typedef int (*ptr)();
>>>>
>>>> int H(ptr x, ptr y)
>>>> {
>>>> x(y); // direct execution of P(P)
>>>> return 1;
>>>> }
>>
>> This code does compile and run correctly.
>
> It might compile as C, but it shouldn't compile as C++, because it's trying
> to call an int(*)() with a parameter, even though that function (that the
> pointer is pointing to does not take any parameter.)
>
> Perhaps if it were an int(*)(void*) and then you reinterpret-cast the
> parameter in order to call it, then it would compile.
>
> As for "runs correctly", I don't see how this "runs correctly". Unless you
> mean an infinite recursion that does nothing "runs correctly".
>
This is the question that I am asking:
Does this program have the specified behavior?
For every H that simulates or executes its input and aborts or does not
abort its input P never reaches its last instruction.
--
Copyright 2021 Pete Olcott
Talent hits a target no one else can hit;
Genius hits a target no one else can see.
Arthur Schopenhauer
[toc] | [prev] | [next] | [standalone]
| From | Anurag Ranjan <anuragranjan630@gmail.com> |
|---|---|
| Date | 2021-11-17 22:00 +0000 |
| Subject | Re: Does this program have the specified behavior? |
| Message-ID | <sn3v58$a87$1@gioia.aioe.org> |
| In reply to | #163432 |
On 17/11/2021 04:46, Wolcott wrote:
> On 11/16/2021 10:10 PM, wij wrote:
>> On Wednesday, 17 November 2021 at 11:33:49 UTC+8, olcott wrote:
>
>
>
#include <stdio.h>
void count(int n)
{
static int d = 1;
printf("n = %d\n", n);
printf("d = %d\n", d);
d++;
if (n > 1)
{
count(n - 1);
}
printf("d = %d\n", d);
}
int main()
{
count(5);
return 0;
}
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c
csiph-web