Gamestudio Links
Zorro Links
Newest Posts
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
1 registered members (AndrewAMD), 1,213 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 pointer in struct with more argument types #431962
10/27/13 09:40
10/27/13 09:40
Joined: Apr 2006
Posts: 159
Latvija
Arrovs Offline OP
Member
Arrovs  Offline OP
Member

Joined: Apr 2006
Posts: 159
Latvija
I ran into problem when i just cant think out that what im showing in example.
Example:
Code:
typedef struct
{
function test();
function test(int i);
}Function_struct

function main()
{
//all initialization
//now adding function to pointer
function_struct.test = some_function;
//so how i can get it to recognize both argument types?
//Like button click function can work with and without arguments
}



Possible i need to use other aproach, but its just example.

I really hope any can give good working one.


Arrovs once will publish game
Re: Function pointer in struct with more argument types [Re: Arrovs] #431963
10/27/13 10:04
10/27/13 10:04

M
Malice
Unregistered
Malice
Unregistered
M



I'm going to ask because I'd like to know for sure.
I thought a Struct couldn't have functions in it - That would be a class?

I asking not telling -
Thanks
Mal

Last edited by Malice; 10/27/13 10:06.
Re: Function pointer in struct with more argument types [Re: ] #431965
10/27/13 12:57
10/27/13 12:57
Joined: Nov 2007
Posts: 318
Brasil, Paraná
NeoNeper Offline
Senior Member
NeoNeper  Offline
Senior Member

Joined: Nov 2007
Posts: 318
Brasil, Paraná
Code:
#define new(type) malloc(sizeof(type##))



typedef struct
{

void fCallback(char *msg);

}DATA;

void vtest2(char* a)
{
	
printf(a);
	
}


function main()
{
	

	level_load(NULL);
	wait(5);
	video_window(nullvector, nullvector, 16|32|64|128, "My Test");
   
   
	DATA* mydata = new(DATA);
	mydata.fCallback=vtest2;
	mydata.fCallback("Hello World");
	
	wait(1);
	free(mydata);
}




Last edited by NeoNeper; 10/27/13 13:02.

Please! Use easy words to be translated. because my English is not very good! Grateful.
_______________________________________________________
Re: Function pointer in struct with more argument types [Re: NeoNeper] #431973
10/27/13 17:19
10/27/13 17:19
Joined: Apr 2006
Posts: 159
Latvija
Arrovs Offline OP
Member
Arrovs  Offline OP
Member

Joined: Apr 2006
Posts: 159
Latvija
NeoNeper: Im using this aprouch already for some time, but im asking how to get it to recognize different paramters.

function test();
function test(int i);

like this two. In struct i can show how many paramters i use for function and it can recognize it, but when i want to let it recognize all types under same name i dont know how to do it.

Malice: Just see NeoNeper example.


Arrovs once will publish game
Re: Function pointer in struct with more argument types [Re: Arrovs] #431974
10/27/13 17:40
10/27/13 17:40
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
You cannot at the moment and you shouldn't. Use unique function names instead.


Always learn from history, to be sure you make the same mistakes again...
Re: Function pointer in struct with more argument types [Re: Uhrwerk] #434087
12/12/13 03:27
12/12/13 03:27
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
FoxHound Offline
Expert
FoxHound  Offline
Expert

Joined: Jun 2004
Posts: 2,234
Wisconsin USA
I know this is old but the info here is wrong.

You can have function pointers in your structs.

typedef struct
{

void* fCallback;
}DATA;


DATA* mydata = new(DATA);
mydata.fCallback=vtest2;
mydata.fCallback("Hello World");

The manual goes into detail on how to use function pointers.


---------------------
There is no signature here.


QUIT LOOKING FOR ONE!
Re: Function pointer in struct with more argument types [Re: FoxHound] #434089
12/12/13 08:06
12/12/13 08:06
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Foxhound, please don't mix C++ and lite c. There is no new operator in lite c. Structs are getting allocated with sys_malloc or one of its relatives. Also you cannot call function pointers directly in lite c. You have to assign them to a prototype first.
Originally Posted By: Malice
I thought a Struct couldn't have functions in it - That would be a class?
As said, a struct can have abitrary pointers to whatever. But that doesn't make it a class. Structs neither support inheritance, nor encapsulation or polymorphism.


Always learn from history, to be sure you make the same mistakes again...
Re: Function pointer in struct with more argument types [Re: Uhrwerk] #434128
12/13/13 22:35
12/13/13 22:35
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
FoxHound Offline
Expert
FoxHound  Offline
Expert

Joined: Jun 2004
Posts: 2,234
Wisconsin USA
I'm not. This is not a function in a class but a function pointer to be kept in a struct. I have several of them in my own code (lite c) and use them quite often.


---------------------
There is no signature here.


QUIT LOOKING FOR ONE!

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