C将一个int分配给一个函数指针
C assign an int to a function pointer
我有一个函数地址存储在 unsigned int
中,还有一个函数指针。
现在我希望 function_pointer
包含 function_address
的值
unsigned int function_address = 0xdeadbeef;
void(*function_pointer)(void) = function_address; // not valid
如何在 C 中做到这一点?
试试这个
typedef void(*function_pointer_type)(void)
function_pointer_type *function_pointer = (function_pointer_type *) address;
执行显式转换。
void(*function_pointer)(void) = (void (*)(void))function_address;
我有一个函数地址存储在 unsigned int
中,还有一个函数指针。
现在我希望 function_pointer
包含 function_address
unsigned int function_address = 0xdeadbeef;
void(*function_pointer)(void) = function_address; // not valid
如何在 C 中做到这一点?
试试这个
typedef void(*function_pointer_type)(void)
function_pointer_type *function_pointer = (function_pointer_type *) address;
执行显式转换。
void(*function_pointer)(void) = (void (*)(void))function_address;