ç下旬未知参数绑定 [英] C late binding with unknown arguments
问题描述
我psently $ P $在我需要调用大量已在运行时被提取函数指针的情况。问题是,参数是在编译时未知。
I am presently in a case where I need to call a lot of function pointers that has been extracted at runtime. The problem is that the arguments are unknown at compilation time.
但是,在运行时我收到DATAS,让我知道该函数的参数,我甚至可以在参数存储在一个char *数组。问题是,我没有一个函数指针模型来扔。
But, at runtime I receive datas that allows me to know the arguments of the function and I can even store the arguments in a char* array. The problem is that I don't have a function pointer model to cast it into.
在高级语言,我知道有类似功能InvokeMethode(字符串名称,字节[]参数),国米preT字节数组类似的论点。由于反射不存在C,我已经没有希望看到与这个函数指针。
In high level language, I know there is function like "InvokeMethode(String name,Byte[] args)" that interpret the bytes array like arguments. Since reflection does not exist in C, I have no hope to see this with a function pointer.
一个解决方案,我有一点(和它的非常糟糕),是建立在编译时函数指针的模式,将在硬codeD方式剧组在PTR为正确的类型使用像这样的:
One solution that I have in mind (and it's really bad), is to create a model of function pointer at compilation time that will cast in a "hardcoded way" the ptr to the right type to use like this:
void callFunc64Bits(void* funcPtr,long long args);
void callFuncVoid(void* funcPtr);
问题是,我将不得不创建一个类似100的功能像这样将正确地转换指针。
The problem is that I will have to create like 100 function like this that will cast the pointer correctly.
有没有办法更有效地做到这一点?
Is there a way to do it more efficiently?
非常感谢你!
推荐答案
这是一个困难的问题没有了,遗憾的是,好简单的答案。
This is a hard problem without, unfortunately, good or easy answers.
请参阅此前者SO问题:<一href=\"http://stackoverflow.com/questions/22169879/run-time-parameters-in-gcc-inverse-va-args-varargs\">Run-time在gcc的参数(反va_args /可变参数)
See this former SO question: Run-time parameters in gcc (inverse va_args/varargs)
请参阅该C FAQ问题: http://c-faq.com/varargs/invvarargs。 HTML
See this C FAQ question: http://c-faq.com/varargs/invvarargs.html
由C常见问题列表维护见本集的古怪的想法// C -faq.com/varargs/wacky.html
See this collection of "wacky ideas" by the C FAQ list maintainer: http://c-faq.com/varargs/wacky.html
附录:看到这个前SO问题:<一href=\"http://stackoverflow.com/questions/12206865/how-to-call-functions-by-their-pointers-passing-multiple-arguments-in-c\">How其指针传递多个参数在C中调用函数?
Addendum: see this former SO question: How to call functions by their pointers passing multiple arguments in C?
...其中提到libffi: http://sourceware.org/libffi/
...which mentions "libffi": http://sourceware.org/libffi/
这篇关于ç下旬未知参数绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!