How to call functions by their pointers passing multiple arguments in C?

前端 未结 1 1611
甜味超标
甜味超标 2020-12-21 18:47

I need to make a \"function caller\" function: it receives a generic function pointer (void *) and a variable number of arguments as arguments and it\'s got to

1条回答
  •  爱一瞬间的悲伤
    2020-12-21 19:17

    The bad news is, this is not possible in C, even in unportable C. (GCC has extensions which sound like they do this job, but they do not work in the general case.) It is necessary to write assembly-language shims.

    The good news is, other people have already written the shims for you: have a look at libffi. (Manual here. Do not use the "closure" API if you can possibly avoid it.)

    0 讨论(0)
提交回复
热议问题