我正在使用 c 中的函数指针,因为我需要自定义 API 库的回调机制。用一个简单的例子总结一下:
*userfunction*(SY_msg msg)
{
/* do something */
};
SY_msg的大小为 1024 字节。因此堆栈中有 1024 个字节。
指向userfuncion()的指针作为 calback_wrapper[] 中的第一个元素存在。
here is an example of use:
// (...) some code
SY_msg* msg;
msg = SYmalloc (sizeof(SY_msg)); /* it takes 1024 bytes in heap */
// (...) some code
calback_wrapper[0] (*msg); /* 1204 are passed by value */
/* during userfunction() execution , 1024 unused bytes are present in the heap */
free (msg); /* now finally heap is free */
// (...) some code
但我想拥有以下内容:
// (...) some code
SY_msg* msg;
msg = SYmalloc (sizeof(SY_msg)); /* it takes 1024 bytes in heap */
// (...) some code
memcpy(someplace,msg,sizeof(SY_msg); /* where "someplace" is a point in the stack referred by the argument of userfunction() */
free (msg); /* heap is free */
calback_wrapper[0] (*someplace); /* is starts userfunction() execution */
// (...) some code
有可能找到“某个地方”的地址吗?我的编译器是 gcc。