Message Board
Message Board > Fenix / Bennu / Gemix / DIV > pointers to structures |
January 4, 2007, 19:38 | |
yonni
None 420 posts |
I have a structure that has been declared like this: Code: global struct astruct[max_int] int anint; string astring; end; And a process that goes a little like this: Code: process aprocess(pointer structure) private int n; begin repeat say(structure[n].astring); n++; until(n > 10); end; the pointer to the structure is made by simply: Code: aprocess(&astruct); so that the "structure" variable contains a pointer to the "astruct" struct. The problem is that I don't know the correct thing to put on the line: Code: structure[n].astring; As this code is (of course) not working. How do you dereference pointers to structures? I know the -> operator, but "structure[n]->astring" or "*structure[n]->astring" does not work. ____________ |
# |
January 4, 2007, 19:45 | |
Eckolin
Quite Whiskered 388 posts |
You are currently using an int pointer. You can declare a type astruct Code: type _astruct; int anint; string astring; end; Then declare an array of that type Code: _astruct astruct[MAX_INT] // MAX_INT? and use an _astruct pointer structure. You should then be able to refer to your string with structure[n].astring. ____________ Maker of Games... Wisdom is supreme; therefore get wisdom. Need help with coding? I probably wrote something similar. |
# |
January 4, 2007, 20:49 | |
Sandman
F3n!x0r 1194 posts |
Unfortunately strings tend to cause problems in Type's. That's why I'm using byte arrays instead of strings. I'm using v0.84a, I don't know about the other versions.
____________ BennuWiki Yes, my avatar has grey borders in IE (so get a decent browser) ROOFLEZ ROOFLEZ |
# |
January 4, 2007, 21:38 | |
yonni
None 420 posts |
So what you're saying Ecko, is that what I need is a pointer structure to point to my structure? 'cause that really isn't worth what I wanted it for.
____________ |
# |
January 5, 2007, 00:20 | |
Sandman
F3n!x0r 1194 posts |
Your code translated to Type's: Code: type _astruct
int anint; string astring; end global _astruct astruct[MAX_INT]; =========== process aprocess(_astruct pointer as) private int n; begin repeat say(as[n].astring); n++; until(n > 10); end; =========== aprocess(&astruct); // Fenix takes &astruct[0] as &astruct automatically =========== as[n].astring; ____________ BennuWiki Yes, my avatar has grey borders in IE (so get a decent browser) ROOFLEZ ROOFLEZ |
# |
January 5, 2007, 09:32 | |
yonni
None 420 posts |
Thanks guys, I understand now. You say strings tend to cause problems with types, can you elaborate on that?
____________ |
# |
Message Board > Fenix / Bennu / Gemix / DIV > pointers to structures