Hi all! I'm doing this class assignment, using classic C, and am stuck with this problem about callback functions that take variable arguments count and type.
Basically, I'm working on a Hashed Tree (a tree where each of the nodes is a hash tree), and I have a certain traversal strategy that will be used multiple times for different purposes, so I implemented it as ht_walk(HashTree tree, (*callback)(Element e)), so that the function called as callback will process the Element whatever way necessary.
Problem being, in most situations in my problem the callback function will have to take different arguments. I know how to design a function with a variable argument list using 'variadic' functions (using stdarg, printf-way), but I don't know how to 'repass' these arguments to the callback function.
Let me provide a concrete example: suppose I have a callback function called addToList(Element e, List list), and that my ht_walk declaration is now ht_walk(HashTree tree, (*callback)(Element e), ...). Consider I want to use ht_walk like in the following snippet:
HashTree my_tree = ht_create();
/* run some algorithm that populates the tree somehow */
List my_list = list_create();
ht_walk(my_tree, addToList, my_list);
Is there a way to do this? Thanks in advance!