Please don't top-post. Your reply should be after, or interspersed
with, any quoted text, which should be trimmed to what's necessary for
context.
"ItayP" <it*******@gmail.com> writes:
Itay wrote:
[...] and somewhere in R5900.c:
Cpu->ExecuteBlock();
ExecuteBlock is not defined anywhere. I did a "search in files" in
the whole project, and the whole project dir...Only references to
ExecuteBlock found..no definition. What's going on here?!
[...]
Ok...Sorry for not knowing about the broken reply link.
I was told that there must be somewhere something similar to that:
void frammis();
...
Cpu->ExecuteBlock = frammis;
(shouldn't it be &frammis?)
anyway, I couldn't find anything similar..
Right. Cpu is a pointer to an object of some struct type. One of the
members of the struct, a pointer-to-function, is named ExecuteBlock.
So ExecuteBlock is the name of the struct member, not the name of a
function.
If frammis is a function compatible with the declaration of
ExecuteBlock, then assigning
Cpu->ExecuteBlock = frammis;
allows you to call frammis indirectly as:
Cpu->ExecuteBlock();
The assignment is the most straightforward way to set the value of
Cpu->ExecuteBlock, but it's not the only way. I would exect a global
search for ExecuteBlock to find the assignment unless something ugly
is being done (like setting it in an assembly language routine,
perhaps?).
The assignment does not require the "&" operator. A reference to a
function name is implicitly converted to a pointer to the function
(unless it's the operand of a sizeof or "&" operator; in the case of
sizeof the result is an illegal expression). So you can use &frammis
if you like, but just frammis is ok.
Note that a function call is one of the contexts in which a function
name is implicitly converted to a pointer. A function call is
effectively an operator whose first operad is a value of an
appropriate pointer-to-function type, so even an ordinary function
call:
myfunc(1, 2);
is really an indirect call through a pointer. (Of course an
implementation is free to optimize this to a more direct form in the
generated code as long as the result is the same.)
Here's a (rather silly) illustration:
#include <stdio.h>
void myfunc(int n)
{
printf("myfunc(%d)\n", n);
}
int main(void)
{
myfunc(1);
(&myfunc)(2);
(*&myfunc)(3);
(*myfunc)(4);
(**myfunc)(5);
(***myfunc)(6);
(*&*&*myfunc)(7);
return 0;
}
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.