Hello.
I was wondering: how should I call a function stored in a separate file that of whom I know nothing but the header?
If I had a function for a queue that takes void* (and therefore I can put anything into it) and I wanted to call the destruction function of the data I'm queueing passing it as a parameter to the destruction function of the queue itself, how should I call it?
LB and dhayden are right, but, even so, I still get two errors.
I've read that void* receiving functions can take any kind of pointer you throw at them, but these errors seem not to agree with that.
pruebas_alumno.c: In function ‘dynamic_mtest’:
pruebas_alumno.c:91:5: error: passing argument 2 of ‘queue_destruction’ from incompatible pointer type [-Werror]
queue_destruction(some_queue, stack_destruction);
^
In file included from pruebas_alumno.c:1:0:
queue.h:31:6: note: expected ‘void (*)(void *)’ but argument is of type ‘void (*)(struct stack_t *)’
void queue_destruction(queue_t* some_queue, void (stack_destruction)(void*));
^
"stack_destruction" is a function in a separate file (stack.c) belonging to an external structure (a stack) that I am including using "#include "queue.h".
I've implemented "stack_destruction" as well, but I've been told that I must treat it as if I didn't knew nothing about it other than pre, post conditions and it's header (which means I can't change what it does, receives or gives back).
What should I do then?
Also, must I copy the header of "stack_destruction" within "queue.c" for it to work? Or just incluing stack.h is enough?
You are not trying to convert from some pointer to void pointer, you are trying to convert from one kind of function to an entirely different kind of function. Don't do that.
I get that I am doing it wrong, but I can't find how to do it right.
I want to pass the whole function as a parameter, not the result, and I don't know how to do that.
The responses above still leave me with the errors in my previous post.