void*-->cast to pointer to function

Status
Not open for further replies.

abdalla

Member level 4
Joined
Mar 22, 2006
Messages
79
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,288
Activity points
1,802
pointer to function as (void *)

Hi

if u please i want to know how to

void*-->cast to--> pointer to function

give example if u pls



thx thx
 

how to cast void * to functions

the pointer pointes to a memory location not the function...
 

cast a void * to pointer to function

Just wrote an example for you
Its C++ style, if you need it C style letme know...

Please give points if it was actually usefull... (need them bad to download a service manual)

Hope it was helpfull




#include <iostream>

void f()
{
std::cout << "Hello world!!!";
}

typedef void (Function)();

int main()
{
// Here we assign f to the void pointer
void* voidPointer = f;

// Here we cast it into Function*
Function* functionPointer = reinterpret_cast<Function*>(voidPointer);

// Now we execute it
(*functionPointer)();
}
 

void * cast to pointer function

pointer to function olso support for several microntroller compiler
 

void * cast to pointer to function c++

Hello
OK, it is simply to do it in C
Take this EX

void* your_vptr;
typedef void (your_func) (param1,param2,param3);
your_func mem_func;
mem_func = (your_func*) your_vptr;

for any question contact me
M.Swedan
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…