Mail Archives: djgpp/1998/06/23/03:15:49
Todd Rowan wrote:
>
> How do you explicity cast a void pointer to a function pointer? Or do you
> even need to cast void pointers manually?
To be able to cast a function pointer to a void pointer is a DJGPP
extension to the C language. It is not standard available in all C
implementations or on all platforms. Please consider that when using it!
void fn(double,double); // example: fn's prototype
void *vp;
vp = (void*)fn; // On older C implementations (pre-ANSI) you had to
write (void*)&fn
Now the answer to the question (note that each brace is required):
fn's type is ((void*)(double,double))
So casting vp to a function pointer of type ((void*)(double,double))
gives:
((void*)(double,double))vp
When you want to call this function with a number of arguments, you have
to write e.g.:
(((void*)(double,double))vp)(3.0,-2.0);
Note that the excessive amount of braces is required.
Note also that I haven't tested any of this, but it should work.
--
\ Vik /-_-_-_-_-_-_/
\___/ Heyndrickx /
\ /-_-_-_-_-_-_/ Knight in the Order of the Unsigned Types
- Raw text -