I don't think pointer comparison with == is type checked in C/C++.
But I could be wrong.
aegisknight
on Mar 16, 2005
GetProcAddress doesn't return void. Like I said, you should actually test and run before you submit answers. ;)
sufianrhazi
on Mar 16, 2005
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.
[HTML_REMOVED]
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;
}
[HTML_REMOVED]
[HTML_REMOVED]no?[HTML_REMOVED]
But seriously, if you managed to pull this off do tell, do tell.
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?
Wut? You're thinking too hard. It's a trivial answer in most languages.
def self(): return self
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. :)
void f(){ return GetProcAddress(loadlibrary("this.dll"),"f"); }
I don't think pointer comparison with == is type checked in C/C++.
But I could be wrong.
GetProcAddress doesn't return void. Like I said, you should actually test and run before you submit answers. ;)
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.
[HTML_REMOVED]
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; } [HTML_REMOVED]