|
1 registered members (TipmyPip),
18,631
guests, and 7
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Functions in structs?
[Re: HeelX]
#179214
01/22/08 12:00
01/22/08 12:00
|
Joined: Jan 2008
Posts: 49 Sweden
Kenchu
OP
Newbie
|
OP
Newbie
Joined: Jan 2008
Posts: 49
Sweden
|
Quote:
Well, I know what you mean. Actually, you cant store functions in structs. Thats why they are called structs: "data structures". Though, the developers said, that they will eventually add functions to structs (which seems odd to me, but, well... okay).
As a solution, you can save a function ptr into an instance of a struct. By this you could write your own routine to execute those functions by passing their pointer which is saved inside the instance.
Yes I know you can do that somehow, but not how exactly. I tried looking for it in the manual, but without success. Also looked in that online book you linked too, which indeed explains how to do it in C. However, when I tried doing it in lite-c, it would complain about syntax errors. I tried having these declarations inside a struct:
Code:
function (*myfunk); function (*myfunk)(); function (*myfunk)(void); int (*myfunk); int (*myfunk)(); int (*myfunk)(void);
Only one at the time of course to try it out. None of the above was allowed.
Quote:
There are good examples in the manual - try them first!
I dont think you understood what I meant. I know how to use them, not how they work. Exactly what do they return? Usually, you'd have to do something like this:
member of struct equals something/function return value i.e. for example
Code:
PANEL* my_panel = { pos_x = 10; pos_y = func_that_returns_a_var(); }
But then we have these string() and digits(), which you dont use in that way. You just invoke them inside an object initialization:
Code:
PANEL* my_panel = { digits(10,10,2,*,1,some_var); }
Why exactly is that allowed? Is it possible for me to define a function that is allowed within an object initialization like that?
Quote:
Code:
typedef struct TRACKPOINT { VECTOR pos; struct TRACKPOINT *parent, *child; } TRACKPOINT;
which saves a vector and two pointers two other instances. As you can see, you can only store data.
About that. Are there any data structures implemented in lite-c already? Kinda like STL in C++ so you wont have to implement your own vectors, lists and maps?
Last edited by Kenchu; 01/22/08 12:16.
|
|
|
|
|
|