小编Raz*_*Raz的帖子

C - 通过func_ptr调用函数,为什么它不起作用?

我有以下代码:

void print(const char* str){
      system_call(4,1,str,strlen(str)); }

void foo2(void){ print("goo \n");}


void buz(void){ ...}

int main(){
char buf[256];
    void (*func_ptr)(void)=(void(*)(void))buf;
    memcpy(buf,foo2, ((void*)buz)-((void*)foo2));
    func_ptr();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

问题是,为什么这个代码会掉下来?

答案是,关于调用函数不是通过指针的东西是相对地址,但我还没有弄清楚这里有什么问题?哪条线是有问题的?

谢谢您的帮助

c pointers function

5
推荐指数
1
解决办法
515
查看次数

标签 统计

c ×1

function ×1

pointers ×1