Thanks, Andy!
It really worked fine.
Odilon J. Bedin
----- Original Message -----=20
From: an...@al...=20
To: Odilon J. Bedin=20
Sent: Friday, February 20, 2004 5:47 AM
Subject: RE: [Dev-C++] Passing function address as a parameter.
Hi,
Maybe try this:
#include <stdio.h>
//Type defintition of pointer to keep the code cleaner - I think this =
was your problem not defining the pointer correctly.
typedef void (*pMyFunc)(void);
void MyFunc(void);
void TestMyFunc(pMyFunc pmf);
int main(int argc, char *argv[])
{
=20
//Pass Function address to Test Function
TestMyFunc(MyFunc);=20
=20
return 0;
}
void MyFunc()
{
printf ("Hello!");
}
void TestMyFunc(pMyFunc pmf)
{
pmf();
}
Hope that helps.
Andy
-----Original Message-----
From: dev...@li... =
[mailto:dev...@li...]On Behalf Of Odilon J. =
Bedin
Sent: 20 February 2004 03:01
To: dev...@li...
Subject: [Dev-C++] Passing function address as a parameter.
Hi !
I'm using DevCpp in games development and I'm having a problem about =
passing function address as a parameter.
Example:
void show_message() {
printf("Message\n");
}
void call_function(void *func) {
// I receive the pointer to de function, but I can't execute it, =
like this:
func();
}
int main() {
call_function((void*)show_message);
getch();
}
In order to execute the function passed as parameter, I have this =
option:
void show_message() {
printf("Message\n");
}
void call_function(void func()) {
// This works fine, but I can't store the address of func() to =
execute it later.
func();
}
int main() {
call_function(show_message);
getch();
}
I've tried some typecasts, but the compiler doesn't accept.
Does anyone here have a suggestion?
Thanks!
Odilon J. Bedin |