• Re: Do this program have the specified behavior?

    From wij@21:1/5 to olcott on Tue Nov 16 20:10:31 2021
    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)
    | ~~~~^

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)