8 thoughts on “Puzzle for Today”

  1. That seems to go against the rules of logic, in a Godelian kind of way…?

    Although by use of recursion, of course. In the strictest sense. But I don’t think that’s what you meant, was it?

  2. Wut? You’re thinking too hard. It’s a trivial answer in most languages.

    def self(): return self

  3. I see. I tried to read into your example that didn’t seem to make much sense. ;) Seemed like you were trying for something grander.

    Anyway, yeah sure you can always use a pointer to self to get its value. :)

  4. GetProcAddress doesn’t return void. Like I said, you should actually test and run before you submit answers. ;)

  5. Pointer comparison isn’t necessarily typechecked, but that’s not the problem. It’s that function pointers must be aware of the type that they’re returning. The problem is, you need to specify that functions need to return pointers of a function type which returns a pointer to a function type which returns… etc.

    As for the casting, this is the *best* solution I came up with.

    #include <assert.h>
    
    typedef void*(*fptr)();
    
    fptr this(){
            return this;
    }
    
    int main(){
            fptr one = this;
            fptr two = this();
            fptr three = (fptr)two();
            fptr four = (fptr)three();
            assert(one == two);
            assert(two == three);
            assert(three == four);
            return 0;
    }
    

Leave a Reply

Your email address will not be published. Required fields are marked *