将函数作为参数传递 [英] passing a function as a parameter
本文介绍了将函数作为参数传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
void dispatch_for(dispatch_queue_t *queue, long number, void (* work)(long)){
int loop = number;
int i;
task_t *ctask;
for(i = 0; i<loop;i++){
ctask = create_task((void *)work,number,"for_test");
dispatch_async(queue,ctask);
}
}
task_t *task_create(void (* work)(void *), void *param, char* name){
//do something
}
我正在作为一个函数工作,需要将它传递给函数 create_task..(第一个参数)
我该如何通过?
I'm getting work as a function and need to pass it to the function create_task..(1st parameter)
How should i pass it?
推荐答案
没有括号的函数名是指向那个函数的指针:
name of the function without the parentheses is the pointer to that function :
void work(void) {
...;
}
void main(void) {
task_create(work, void, void);
}
这篇关于将函数作为参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文