Originally Posted by
keira
What is this code: "int (*callback)(int index, int item, void *param)" really saying?
What would the asm look like?
The "prototype" that you have for
Code:
int (*callback)(int index, int item, void *param)
is there so that the compiler can check that you have a sensible function as the callback.
In this case, it says "callback" is a pointer, to a function that returns an in, and the function takes two integer and one void * parameter.
It really makes no difference to the compiler as such if you were to pass a function pointer to a function that takes one parameter, or 15 parameters - but because it's probably not the right thing to do, we have taught the compiler to tell us when we get it wrong.
callback itself is just a pointer - it happens to be a pointer to some function, and when it is being used later on in the code.
But for the call to "traverseWith", all it will do is pick up a 32 (or 64) bit pointer to the function you want to use, and store that so that the traverseWith function can use it to call the callback function.
Inside traversewith, you'll find some code that looks something like this:
Code:
....
mov param[esp], eax
push eax
mov index[esp], eax
push eax
mov item[esp], eax
push eax
mov callback[esp], eax
call eax
....
Appologies for unaligned spacing on the assembler code.
--
Mats