Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
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
1 registered members (henrybane), 1,499 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
get pointer of an overloaded function #258894
04/02/09 18:22
04/02/09 18:22
Joined: Mar 2009
Posts: 112
Germany
K
KDuke Offline OP
Member
KDuke  Offline OP
Member
K

Joined: Mar 2009
Posts: 112
Germany
I wonder how and if it is possible to retrieve the pointer of an overloaded function.
If I have
Code:
var MyFunction(var a)
{
   return a*a;
}


I can get the pointer to the function by using solely it's name like
Code:
void* functionPointer = MyFunction


Though how can I get a pointer to a specific overloaded function like this?
Code:
var MyFunction(var a) //I'll call this first function
{
  return a*a;
}

var MyFunction(var a, var b) //and this second function
{
   return a*b;
}


So how can I get the pointer to the second function now?
Overloaded function are differenciated by their parameters. Though if I give parameters it will execute the function and give the function's return value instead of the pointer to it!

greetings
K-Duke


Using A7 Free
Click and join the 3dgs irc community!
Room: #3dgs
Re: get pointer of an overloaded function [Re: KDuke] #258911
04/02/09 19:48
04/02/09 19:48
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Why do you need a pointer to one specific overload? Doesnt the pointer you have (in essence) point to all the overloads?

When using the pointer, give the parameters you want to pass, and it will pick the correct overload, doesnt it?
(Ive never tried, so this is an educated guess)

Or do you want the pointer to a specific overload for some other reason?


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: get pointer of an overloaded function [Re: EvilSOB] #258915
04/02/09 20:09
04/02/09 20:09
Joined: Mar 2009
Posts: 112
Germany
K
KDuke Offline OP
Member
KDuke  Offline OP
Member
K

Joined: Mar 2009
Posts: 112
Germany
Actually overloaded functions are stored at different positions in memory.
They get a decorated name (just google for 'overloading +"decorated names"') and then they are individually callable by their pointer. That's just what the compiler does. It replaces func(int x) with the pointer to code memory space x and func(var x) with the pointer to code memory space y and gives the parameters to these functions.

The actual thing I want to achieve is having imported functions from a dll( as one has to export DLL functions for Lite-C as C type and not C++ the DLL itself won't support overloaded functions). Though I thought if I'm able to get the pointer to an overloaded Lite-C function I can assign dllfunc1 to the one and dllfunc2 to the other overloaded function by getting the pointer to the functionpointer. And getting that would only be a "&" far away if I had the appropriate functionpointer.

In C++ it would be as simple as the following.
Code:
int myfunction(int x)
{  whatever... }

int myfunction(double x)
{  whatever ... }

void* myFunctionPointer;
int (*myFunctionPointer)(int) = myfunction;  //after this line myFunctionPointer is pointing to the first myfunction.
int (*myFunctionPointer)(double) = myfunction; // after that one it is pointing to the second.

greetings
K-Duke

Last edited by KDuke; 04/02/09 20:10.

Using A7 Free
Click and join the 3dgs irc community!
Room: #3dgs
Re: get pointer of an overloaded function [Re: KDuke] #258922
04/02/09 21:33
04/02/09 21:33
Joined: Mar 2009
Posts: 112
Germany
K
KDuke Offline OP
Member
KDuke  Offline OP
Member
K

Joined: Mar 2009
Posts: 112
Germany
Darn... really!
Couldn't see the forest for the trees!

So I got the following functions imported from a DLL:
Code:
var dllFunc1(int x);
var dllFunc2(var x);


now to get an overloaded function in Lite-C from those two one can simply do the following
Code:
var myOverloadedLiteCFunc(int x)
{
  return dllFunc1(x);
}

var myOverloadedLiteCFunc(var x)
{
  return dllFunc2(x);
}


So no need to get functionpointers or even pointers to pointers or such ugly stuff laugh

Though I'm feeling so dense!

greetings
K-Duke


Using A7 Free
Click and join the 3dgs irc community!
Room: #3dgs

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