473,466 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using a function that doesn't exist =\

While going through the code of the open source project PCSX2
(www.pcsx2.net - PS2 emulator for windows and linux. source code can be
d/led from here: http://tinyurl.com/6242p), I saw a strange (at least
for me...) thing:
in the R5900.h header (hmm..emulating a CPU...), there's a struct which
looks like this:
typedef struct {
int (*Init)();
void (*Reset)();
void (*Step)();
void (*Execute)();
void (*ExecuteBlock)();
void (*ExecuteVU0Block)();
void (*ExecuteVU1Block)();
void (*EnableVU0micro)(int enable);
void (*EnableVU1micro)(int enable);
void (*Clear)(u32 Addr, u32 Size);
void (*ClearVU0)(u32 Addr, u32 Size);
void (*ClearVU1)(u32 Addr, u32 Size);
void (*Shutdown)();
} R5900cpu;

and then

R5900cpu *Cpu;

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?!

It must be found somehwere, because it's in a function that's - CMIIW -
always called (indirectly) from WinMain ...and it doesn't make sense
that it's accidently there...
Any explanation?

thanks,

Itay
Nov 14 '05 #1
12 1274


Itay wrote:
While going through the code of the open source project PCSX2
(www.pcsx2.net - PS2 emulator for windows and linux. source code can be
d/led from here: http://tinyurl.com/6242p), I saw a strange (at least
for me...) thing:
in the R5900.h header (hmm..emulating a CPU...), there's a struct which
looks like this:
typedef struct {
int (*Init)();
void (*Reset)();
void (*Step)();
void (*Execute)();
void (*ExecuteBlock)();
void (*ExecuteVU0Block)();
void (*ExecuteVU1Block)();
void (*EnableVU0micro)(int enable);
void (*EnableVU1micro)(int enable);
void (*Clear)(u32 Addr, u32 Size);
void (*ClearVU0)(u32 Addr, u32 Size);
void (*ClearVU1)(u32 Addr, u32 Size);
void (*Shutdown)();
} R5900cpu;

and then

R5900cpu *Cpu;

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?!

It must be found somehwere, because it's in a function that's - CMIIW -
always called (indirectly) from WinMain ...and it doesn't make sense
that it's accidently there...
Any explanation?


The things in the struct are *pointers* to functions,
not function names. Somewhere you should find something
like

void frammis();
...
Cpu->ExecuteBlock = frammis;

.... and once this has been done, `Cpu->ExecuteBlock()'
behaves as if you had written `frammis()' instead. What
you need to do is find the assignment or initialization,
make note of the name assigned ("frammis"), and then search
for the function with that name.

--
Er*********@sun.com

Nov 14 '05 #2
Can't find it anywhere!
What's going on here? =\

Nov 14 '05 #3
ItayP wrote:

Can't find it anywhere!
What's going on here? =\


/= ?

--
pete
Nov 14 '05 #4
wtf?

Nov 14 '05 #5
"ItayP" <it*******@gmail.com> writes:
Can't find it anywhere!
What's going on here? =\


Sorry, I have no idea what you're talking about, since you didn't
provide any context (and my news server doesn't have the parent
article).

As we've said here many many times:

"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers."

--
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.
Nov 14 '05 #6
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..
Itay wrote:
While going through the code of the open source project PCSX2
(www.pcsx2.net - PS2 emulator for windows and linux. source code can be d/led from here: http://tinyurl.com/6242p), I saw a strange (at least for me...) thing:
in the R5900.h header (hmm..emulating a CPU...), there's a struct which looks like this:
typedef struct {
int (*Init)();
void (*Reset)();
void (*Step)();
void (*Execute)();
void (*ExecuteBlock)();
void (*ExecuteVU0Block)();
void (*ExecuteVU1Block)();
void (*EnableVU0micro)(int enable);
void (*EnableVU1micro)(int enable);
void (*Clear)(u32 Addr, u32 Size);
void (*ClearVU0)(u32 Addr, u32 Size);
void (*ClearVU1)(u32 Addr, u32 Size);
void (*Shutdown)();
} R5900cpu;

and then

R5900cpu *Cpu;

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?!

It must be found somehwere, because it's in a function that's - CMIIW - always called (indirectly) from WinMain ...and it doesn't make sense
that it's accidently there...
Any explanation?

thanks,

Itay


Nov 14 '05 #7
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.
Nov 14 '05 #8
On 17 Apr 2005 12:24:24 -0700, in comp.lang.c , "ItayP"
<it*******@gmail.com> wrote:
wtf?


Pete meant "wtf r u babln abt?"

Or alternatively, post a meaningful question, don't post gibberish
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
Nov 14 '05 #9
Itay wrote:
typedef struct {
int (*Init)();
void (*Reset)();
void (*Step)();
void (*Execute)();
void (*ExecuteBlock)();
void (*ExecuteVU0Block)();
void (*ExecuteVU1Block)();
void (*EnableVU0micro)(int enable);
void (*EnableVU1micro)(int enable);
void (*Clear)(u32 Addr, u32 Size);
void (*ClearVU0)(u32 Addr, u32 Size);
void (*ClearVU1)(u32 Addr, u32 Size);
void (*Shutdown)();
} R5900cpu;

and then

R5900cpu *Cpu;

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.


Perhaps it is initialized rather than assigned. If you
search for 'Cpu' you should see where it's assigned to
something (obviously you can't write Cpu-> ..... without
first setting Cpu to point to something).

For example the code might be something like:

R5900cpu foo =
{ &foo_Init, &foo_Reset, &foo_Stop, ............ };

and then

Cpu = &foo;
Cpu->Init();

Nov 14 '05 #10
Keith Thompson wrote:
"ItayP" <it*******@gmail.com> writes: [...]
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?!

[...] 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?).


Maybe *Cpu was assigned a struct literal?

--
Nov 14 '05 #11
if (Config.Cpu) Cpu = &intCpu;
#ifdef __i386__
else Cpu = &recCpu;
#endif

Ahaaa!!! :D

Keith Thompson wrote:
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.

Nov 14 '05 #12
"ItayP" <it*******@gmail.com> writes:
if (Config.Cpu) Cpu = &intCpu;
#ifdef __i386__
else Cpu = &recCpu;
#endif

Ahaaa!!! :D

Keith Thompson wrote:
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.

[snip]

Read this again, carefully:

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.

--
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.
Nov 14 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Phi | last post by:
Hi there, I've just started learning php and I hope you guys could help me with this problem. I've found a useful pice of code from a book to make a form and I would like to use it. I would like...
28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
3
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked...
1
by: Daveyk0 | last post by:
Hello there, I have a front end database that I have recently made very many changes to to allow off-line use. I keep copies of the databases on my hard drive and link to them rather than the...
19
by: Kamilche | last post by:
I have looked at many object-oriented programming frameworks out there for C. Though the ideas presented are intriguing, and I've used some of them in my own work, they all suffered some drawback...
18
by: Jen | last post by:
I'm using Microsoft's own VB.NET FTP Example: http://support.microsoft.com/default.aspx?scid=kb;en-us;832679 I can get the program to create directories, change directories, etc., but I can't...
11
by: sara | last post by:
I am trying my first functions in my code. I have a set of queries that runs to create temp tables with the right data for some reports. They can run for a long time, so I want the user to know...
1
by: Bombtrack | last post by:
I have some javascript code that errors in FireFox, but only when I use a DOCTYPE expression at the top of the page - until I added that, it worked fine in both IE and FireFox. Here is the...
3
by: brook | last post by:
hey all - i´m new to php and having trouble writing a simple code which should create a file. here is the most simplified version: <?php $content = "my content"; $path = "test.txt";...
34
by: Davy | last post by:
Hi all, I am writing a function, which return the pointer of the int. But it seems to be wrong. Any suggestion? int * get_p_t(int t) { return &t; } int main()
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.