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>Stack overflow...
#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);
}
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.
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.
On 11/16/2021 10:10 PM, wij wrote:
On Wednesday, 17 November 2021 at 11:33:49 UTC+8, olcott wrote:
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 113 |
Nodes: | 8 (1 / 7) |
Uptime: | 42:18:17 |
Calls: | 2,498 |
Files: | 8,651 |
Messages: | 1,908,057 |