Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 01:28
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
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Ayumi), 838 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
function pointers #416623
02/02/13 14:12
02/02/13 14:12
Joined: Mar 2012
Posts: 44
A
Abarudra Offline OP
Newbie
Abarudra  Offline OP
Newbie
A

Joined: Mar 2012
Posts: 44
Hello me again laugh

i have a "small" question about function pointers. If i am right function paramters can also be pointers to another function.

If i write two functions like this:
Code:
function test()
{
   beep();
}

function calling_func(function* f)
{
   ... // not sure what to write here cause f; or f(); wont work
}


What do i have to insert in "calling_func", so that this syntax
Code:
calling_func(test);


would let me hear the "beep()" sound.
Currently i only get "Call function @t_04018 error" <- no ideo what this means.

I'm gratefull for any help.
regards

Re: function pointers [Re: Abarudra] #416624
02/02/13 14:18
02/02/13 14:18
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
The correct way is:

Code:
void foo(void *f)
{
    void fp(); // The signature should obviously match with the one of the function

    fp = f; // Note that you won't get any help from the static typesystem here, so know what you are doing!
    fp();
}

foo(test); // Or just pass beep directly here



Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: function pointers [Re: Abarudra] #416625
02/02/13 14:22
02/02/13 14:22
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Code:
void test()
{
    beep();
}

function calling_func(void* p)
{
    void f();
    f = p;
    f();
}


Pleas be aware your function "test" does not return anything and hence should be declarated as void, not function.

Last edited by Uhrwerk; 02/02/13 14:22. Reason: Nijnad by JustSid. :-(

Always learn from history, to be sure you make the same mistakes again...
Re: function pointers [Re: Uhrwerk] #416626
02/02/13 15:07
02/02/13 15:07
Joined: Mar 2012
Posts: 44
A
Abarudra Offline OP
Newbie
Abarudra  Offline OP
Newbie
A

Joined: Mar 2012
Posts: 44
thank you both of you.
I will keep your warnings in mind and test your examples.
Maybe i will find another solution to avoid the possible problems i get with this code.

regards


Last edited by Abarudra; 02/02/13 15:08.
Re: function pointers [Re: Abarudra] #416641
02/02/13 18:30
02/02/13 18:30
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
The solutions are perfectly fine and you don't need another one. Just declare functions that do not return anything as void and the other ones with the corresponding type.
Code:
function foo()
{
    return 1337; // Always return values from functions.
    // When using "function" returns a var, when using int return an int etc.
}

void bar()
{
    return; // Don't return a value when using void.
}



Always learn from history, to be sure you make the same mistakes again...

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