Alex Ionescu wrote:
All architectures have an ABI that defines which
registers are used for
return values, and so the compiler will NEVER (under ANY circumstances)
assume that the return register should somehow be "usable", especially
for an external function pointer!
Like I said I don't know if any "real-world" architecture depends on
this. I can however make up my own instruction set where it does matter.
Furthermore, this is typecasting from a ULONG to a
VOID, isn't it? So
the "real" function will never return anything in the first place,
making this a non-issue.
It's not a typecast of a return value, it's a typecast of a pointer to a
function with an incompatible function signature. It's like passing a
callback function with 1 argument to a routine that expects a callback
with 2 arguments. Except that in this instance it would most likely
cause trouble on most architectures immediately. However, it's no
different from the problem I described, except that it happens to be not
much of an issue on x86.
I challenge you to provide a test case/example on any
architecture where
this could possibly happen. It can't.
If I had the time I would be more than happy to come up with a new
architecture where it does make a difference.
It doesn't change the fact that it's a non-portable hack.
- Thomas