Bionix1441 Bionix1441 - 3 months ago 8
C Question

Cast a function pointer to a long

I am not sure if that is feasible, but I need to cast a function pointer to long in order to map C level code back to java code.

Answer

a pointer's value is a integer,you just need know what exactly you are doing and alloc enough storage to store the pointer's value.(int a 32bit os,pointer occupy 32bit storage,int a 64bit os,pointer occupy 64bit storage).

a c example:

#include <stdio.h>



void fun()
{
    printf("fun\n");
    return;
}

typedef void (*fun_type)();

int main()
{
    long long int a = (long long int)fun;

    fun_type func_point = (fun_type)a;

    func_point();
    return 0;
}
Comments