我有一个存储在unsigned int
中的函数地址和一个函数指针。C给函数指针分配一个int
现在我想的是function_pointer
将包含function_address
unsigned int function_address = 0xdeadbeef;
void(*function_pointer)(void) = function_address; // not valid
怎么做,在C值?
我有一个存储在unsigned int
中的函数地址和一个函数指针。C给函数指针分配一个int
现在我想的是function_pointer
将包含function_address
unsigned int function_address = 0xdeadbeef;
void(*function_pointer)(void) = function_address; // not valid
怎么做,在C值?
进行显式类型转换。
void(*function_pointer)(void) = (void (*)(void))function_address;
ahh nice thx very – test123423
@ test123423,欢迎您。 –
试试这个
typedef void(*function_pointer_type)(void)
function_pointer_type *function_pointer = (function_pointer_type *) address;
PSA:不要使用'unsigned int'来存储地址。在某些平台上(比如x86_64 Linux),int值小于指针。为此,使用'uintptr_t'类型。 – fuz