Gamestudio Links
Zorro Links
Newest Posts
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 1,485 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Passing function pointers with parameters #229816
09/30/08 18:25
09/30/08 18:25
Joined: May 2008
Posts: 123
B
BES Offline OP
Member
BES  Offline OP
Member
B

Joined: May 2008
Posts: 123
Hey all!

I define a function pointer (globally defined):
void myFunc( myStruct* ptrStruct );

and give it a default definition:
void myFunc( myStruct* ptrStruct )
{
diag("\nOriginal function called, override this!");
}

Now the function I want to actually call:
void myDesiredFunc( myStruct* ptrStruct )
{
diag("\nCorrect function called");
}

Here's where the issue comes in- I need to set my function pointer in an intermediary function that is part of the API I'm building:
void SetMyFunction( function* newfunc )
{
myFunc = (function*)newfunc;
}

myStruct myStructInstance;
in main()
{
...
SetMyFunction( myDesiredFunc );
myFunc( &myStructInstance );
...
}

But the original function definition is used.
The function pointer (myFunc) and structure pointer parameter are globally defined. I've tried several casts in the SetMyFunction function (i.e. function*, function, void*, etc.)
Anyone see what I'm missing? Do I need to somehow specify the parameter type in my cast; something like
myFunc = (function(myStruct*))newfunc; //??

Thanks so much for your time!

Re: Passing function pointers with parameters [Re: BES] #229824
09/30/08 19:32
09/30/08 19:32
Joined: May 2008
Posts: 123
B
BES Offline OP
Member
BES  Offline OP
Member
B

Joined: May 2008
Posts: 123
Alright, got it:

void SetMyFunction( void* newfunc )
{
myFunc = (function*)newfunc;
}

The problem was using the same name for myFunc and the default definition. To get around this I just say:
void myFunc( myStruct* ptrStruct );

and

void defaultFunc( myStruct* ptrStruct );
{
diag("\nDefault function called!");
}

then in main:

myFunc = defaultFunc

Then I'm able to set myFunc to myDesiredFunc later on.

Hope this helps someone in the future! Cheers!


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1