Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by Zheka. 06/20/24 14:26
Lapsa's very own thread
by rki. 06/19/24 11:27
A simple game ...
by VoroneTZ. 06/18/24 10:50
Face player all the time ...
by bbn1982. 06/18/24 10:25
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,194 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
squik, AemStones, LucasJoshua, Baklazhan, Hanky27
19060 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