【发布时间】:2013-01-07 20:29:08
【问题描述】:
我正在开发一个链表库,这是我写的一个函数:
/**
* go through a linked list and perform function func for every node of the
* linked list
*
* func is a function pointer to the function you would to apply on the node.
* it should return 0 if it is successful and non-zero value otherwise.
*/
void traverse_list(linkedlist * ll, int (* func)(void * args)){
node * temp;
temp = ll->head;
while( temp != NULL ){
if((* func)(temp->val))
fprintf(stderr,"Error processing value!\n");
temp = temp->next;
}
}
我的问题很简单,我尝试了travers_list(testlinkedlist,printf) 之类的方法,但它无法正常工作(printf 没有打印任何内容),我做错了什么?我能做到吗,如果可以的话,怎么做?
【问题讨论】:
-
你绝对可以做到。不确定我脑海中的语法。
-
你可以在函数指针之间进行转换,但实际的错误信息是什么?
-
@Falmarri:我认为这个问题是关于 variadic 函数指针的语法,所以不是重复的。
标签: c pointers linked-list function-pointers