Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
3 registered members (AndrewAMD, TipmyPip, OptimusPrime), 15,359 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
An Example Please :) #411497
11/17/12 14:04
11/17/12 14:04
Joined: Nov 2011
Posts: 139
India
Yashas Offline OP
Member
Yashas  Offline OP
Member

Joined: Nov 2011
Posts: 139
India
I need an example in which there is a function and a function pointer.The function pointer will point to the function and must call the function through the pointer.

Thanks


Keep smiling laugh
http://translation.babylon.com/ - Translate many languages
Re: An Example Please :) [Re: Yashas] #411498
11/17/12 14:11
11/17/12 14:11
Joined: May 2009
Posts: 5,377
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,377
Caucasus
Is this what you need?
Code:
var pointer_function(); // pointer
// function to call pointer function:
function call_pointer_function(){
   pointer_function();
}
// pointer function itself:
function pointer_function(){
}



Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: An Example Please :) [Re: 3run] #411500
11/17/12 14:23
11/17/12 14:23
Joined: Nov 2011
Posts: 139
India
Yashas Offline OP
Member
Yashas  Offline OP
Member

Joined: Nov 2011
Posts: 139
India
I was trying something like this but did not work

int * p;
int _function ()
{
error("I never get here, I get some @func_[somenumber] error");
}
int main()
{
p = &_function;
*p();
}


Keep smiling laugh
http://translation.babylon.com/ - Translate many languages
Re: An Example Please :) [Re: 3run] #411501
11/17/12 14:24
11/17/12 14:24
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
...or do you need something like this:
Code:
#include <acknex.h>

void * void_pointer(); // create a pointer to a 'void'

void test_function()
{
	printf("test");
}

void main()
{
	void_pointer = test_function; // the pointer should point to 'test_function'
	void_pointer(); // call the void the pointer points to
}



POTATO-MAN saves the day! - Random
Re: An Example Please :) [Re: Kartoffel] #411502
11/17/12 14:27
11/17/12 14:27
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
oh you were some seconds faster.
heres the fixed version of your code wink
Code:
#include <acknex.h>

int * p(); // <-- needs ()
int _function()
{
	error("works now.");
}

void main()
{
	p = _function; // <-- without &
	p();
}



...and next time please use [code] and [/code] to make your code better readable smile

Last edited by Kartoffel; 11/17/12 14:28.

POTATO-MAN saves the day! - Random
Re: An Example Please :) [Re: Kartoffel] #411506
11/17/12 14:41
11/17/12 14:41
Joined: Nov 2011
Posts: 139
India
Yashas Offline OP
Member
Yashas  Offline OP
Member

Joined: Nov 2011
Posts: 139
India
How do I take a function as a function parameter ,heres what I have done but causes an error

Code:
void SetTimer (int * p,int time,void * func)
{
	while(*p > 0)
	{
		wait((time * -1));
	}
        if(func) {  func(); }	
}



It does not work, why??


Keep smiling laugh
http://translation.babylon.com/ - Translate many languages
Re: An Example Please :) [Re: Yashas] #411509
11/17/12 14:49
11/17/12 14:49
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Done a bit of testing wink
Code:
#include <acknex.h>

void TestFunction()
{
	error("TestFunction was called");
}

void CallFunc(void * func)
{
	void * temp_void();
	temp_void = func;
	
 	if(temp_void) { temp_void(); }	
}

void main()
{
	CallFunc(TestFunction);
}



POTATO-MAN saves the day! - Random
Re: An Example Please :) [Re: Kartoffel] #411510
11/17/12 14:51
11/17/12 14:51
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
I would like to point out that none of Kartoffels declared return types matches with what the actual function returns.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: An Example Please :) [Re: WretchedSid] #411529
11/17/12 15:13
11/17/12 15:13
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
well would you then please consider about telling us how to do it right? -.-

Last edited by Kartoffel; 11/17/12 15:13.

POTATO-MAN saves the day! - Random
Re: An Example Please :) [Re: Kartoffel] #411531
11/17/12 15:15
11/17/12 15:15
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
It's "void temp_void();" temp_void returns void not a void pointer.


Always learn from history, to be sure you make the same mistakes again...
Page 1 of 2 1 2

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

Gamestudio download | 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