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.