Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
3 registered members (AndrewAMD, Grant, Neb), 908 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Lite_C can use Function pointer in Struct,it is OOP by Lite_C #399615
04/17/12 18:24
04/17/12 18:24
Joined: Dec 2009
Posts: 128
China
frankjiang Offline OP
Member
frankjiang  Offline OP
Member

Joined: Dec 2009
Posts: 128
China
did Lite_C can use by lw_oopc?

Function pointers
In C/C++, function pointers are declared like this: int (*foo)(int a, int b);. In lite-C there's no difference between function prototypes and function pointers: int foo(int a, int b);. See details under pointers.
Function pointers
Pointers of functions or actions can be defined as FUNCTION* under C-Script. LC Under lite-C a function pointer is defined just as a function prototype with return and parameter types. Example:
float myfunction(int a, float b); // define a function pointer named "myfunction"

float fTest(int a, float b) { return (a*b); }
...
myfunction = fTest;
x = myfunction(y,z);


Can I want to use function pointer in Struct in Lite-C?

Code:
typedef struct
{
    int _var;
    int Add(int a, int b);

}Hello;

int fTest(int a, int b) { return (a+b); }
int ATest(int a, int b) { return (a-b); }


Hello* InitHello(Hello* pHello,void* functionPoint)
{
    pHello->Add = functionPoint;
}

void main(){
    Hello A;
    InitHello(A,ATest);
    int Test(int a, int b) ;
    Test =  A.Add;
    printf("%d\n%p\n%p %d",sizeof(A),fTest,A.Add,Test(2,5));
} :eek:



Last edited by frankjiang; 04/17/12 19:19.

development 3d game is interesting!
Re: Lite_C can use Function pointer in Struct,it is OOP by Lite_C [Re: frankjiang] #399624
04/17/12 19:56
04/17/12 19:56
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline
Serious User
PadMalcom  Offline
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
Yes you can use function pointers in structs in Lite-C.


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