c - Given a char* with the prototype, can we cast a void* to a function pointer? and run it? -
i've declared many functions in 1 driver, , passing pointers functions driver in list node format:
struct node { char def_prototype[256]; //example:(int (*)(wchar, int, int)) void *def_function; };
is there way typecast def_function prototype given in def_prototype?
currently i'm using simple switch , strcmp, wanted generalize if possible.
ps: know casting between void pointer , function pointer unsafe (as mentioned in various places in so), desperate times call desperate measures , have taken lot of care.
edit:
sorry lack in clarity. want call function (not cast it), making function pointer @ runtime based on char[] provided.
edit again:
since i'm working @ kernel level (windows driver), don't have access resources, so, i'm sticking current implementation (with changes kill back-doors). help.
a implementation of similar ideas libffi. implements gory details of declaring , calling functions arbitrary calling conventions , signatures. (surprisingly) platform portable, , known work on linux , windows out of box.
an example of use lua extension library alien. demonstrates calling arbitrary functions declared @ runtime , adapting native lua types types required calling conventions. specific lua binding won't useful you, serves complete working example of how , why 1 might use libffi.
Comments
Post a Comment