Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, VoroneTZ), 831 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Redefining the same function in three way. #479557
04/06/20 05:35
04/06/20 05:35
Joined: Jul 2007
Posts: 619
Turkey, Izmir
Emre Offline OP
User
Emre  Offline OP
User

Joined: Jul 2007
Posts: 619
Turkey, Izmir
Hi everybody. I have to ask this question because my programming knowledge is not good.

i want to use the skill of panel as strings, as follows;

Code
test_panel.skill_x=str_create("");


No problem but every time i want to perform string operation, i have to specify that the skill is STRING*.
Code
str_cpy((STRING*)test_panel.skill_x,"test");

But i don't want to do that because it's annoying. So i redefined (i don't know if this is right word) str_cpy function in three different ways like this;

Code
#ifndef str_cpy
	function str_cpy(var var1,STRING* str)
	{
		str_cpy((STRING*)var1,str);
	}
	function str_cpy(STRING* str,var var1)
	{
		str_cpy(str,(STRING*)var1);
	}
	function str_cpy(var var1,var var2)
	{
		str_cpy((STRING*)var1,(STRING*)var2);
	}
#endif


it works without problem. With this way, i can use "str_cpy" function for copy "string to skill" or opposite, or "skill to skill" without use STRING* pointer.


My question: is there any harm in this method? is it safe using this way?

Re: Redefining the same function in three way. [Re: Emre] #479583
04/07/20 13:07
04/07/20 13:07
Joined: Jul 2007
Posts: 619
Turkey, Izmir
Emre Offline OP
User
Emre  Offline OP
User

Joined: Jul 2007
Posts: 619
Turkey, Izmir
Ok. i found the answer. Function overloading.

Re: Redefining the same function in three way. [Re: Emre] #479597
04/09/20 14:42
04/09/20 14:42
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Hi,
I would go with macros. Something like this:

Code
#define s_cpy(x, y)  str_cpy((STRING*)x, (STRING*)y)


And then use 's_cpy' instead of 'str_cpy' for every kind of data. It allows using char pointers or literals as second parameter too.

Salud!

Re: Redefining the same function in three way. [Re: txesmi] #479601
04/09/20 17:42
04/09/20 17:42
Joined: Jul 2007
Posts: 619
Turkey, Izmir
Emre Offline OP
User
Emre  Offline OP
User

Joined: Jul 2007
Posts: 619
Turkey, Izmir
Using macros seems more sensible indeed. Thank you, txesmi!

Re: Redefining the same function in three way. [Re: Emre] #479603
04/09/20 18:35
04/09/20 18:35
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Glad of been of help laugh


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