在 C 中构建函数调用

标签 c linux gcc function arguments

假设我有一个指向函数的指针(例如由 dlsym() 提供)和一个类型化参数的链表,我如何构造一个带有这些参数的 C 函数调用?

例子:

struct param {
   enum type { INT32, INT64, STRING, BOOL } type;
   union { int i32; long long i64; char *str; bool b; } value;
   struct param *next;
 };
 int call_this(int (*function)(), struct param *args)
 { 
     int result;
     /* magic here  that calls function(), which has a prototype of
     f(int, long long, char *, bool); , when args consist of a linked list of
     INT32, INT64, STRING, BOOL types. */
     return result;
 }

操作系统是Linux。我希望该解决方案能够跨 MIPS、PPC 和 x86(所有 32 位)架构移植,使用 GCC 作为编译器。

谢谢!

最佳答案

您可能需要使用 libffi .

关于在 C 中构建函数调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2818424/

相关文章:

php - 如何确定一个列表是否是另一个列表的子集?

c - 用C语言写入文件

linux - 我在哪里可以获得 IoOutput8 () 的源代码

c++ -/usr/lib64/libstdc++.so.6 : version `CXXABI_1.3.8' not found when loading R packages

c - 反汇编 MIPS 架构(isa32r2)的库的起点是什么?

c - 设置 MACRO 的范围

c++ - 在c++中通过字符串获取输入

linux - NXP i.MX6 上的嵌入式 Electron

linux - 如何编译 baremetal hello_world.c 并在 qemu-system-aarch64 上运行?

linux - 在 C 中访问共享内存 SIGSEGV 段错误?