Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #82369 > 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 | 12 — 7 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
Re: Do this program have the specified behavior? wij <wyniijj@gmail.com> - 2021-11-16 20:10 -0800
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? olcott <NoOne@NoWhere.com> - 2021-11-17 08:33 -0600
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 | wij <wyniijj@gmail.com> |
|---|---|
| Date | 2021-11-16 20:10 -0800 |
| Message-ID | <2ce7a201-45d4-49aa-a512-2ca01a4fbd36n@googlegroups.com> |
| In reply to | #82369 |
On Wednesday, 17 November 2021 at 11:33:49 UTC+8, olcott wrote:
> #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
I would guess yes, it is specified: BAD, illegal program
[]$ g++ t.cpp
t.cpp: In function ‘int H(ptr, ptr)’:
t.cpp:6:2: error: too many arguments to function
6 | x(y); // direct execution of P(P)
| ~^~~
t.cpp: In function ‘int main()’:
t.cpp:18:3: error: invalid conversion from ‘int (*)(ptr)’ {aka ‘int (*)(void (*)())’} to ‘ptr’ {aka ‘void (*)()’} [-fpermissive]
18 | H(P, P);
| ^
| |
| int (*)(ptr) {aka int (*)(void (*)())}
t.cpp:4:11: note: initializing argument 1 of ‘int H(ptr, ptr)’
4 | int H(ptr x, ptr y)
| ~~~~^
t.cpp:18:6: error: invalid conversion from ‘int (*)(ptr)’ {aka ‘int (*)(void (*)())’} to ‘ptr’ {aka ‘void (*)()’} [-fpermissive]
18 | H(P, P);
| ^
| |
| int (*)(ptr) {aka int (*)(void (*)())}
t.cpp:4:18: note: initializing argument 2 of ‘int H(ptr, ptr)’
4 | int H(ptr x, ptr y)
| ~~~~^
[toc] | [prev] | [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 | #82370 |
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 | #82371 |
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 | 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 | #82372 |
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 | 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 | #82371 |
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 | #82373 |
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 | #82375 |
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 | #82377 |
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 | #82378 |
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 | #82377 |
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 | #82371 |
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