From: | Colin Wenzel |
Date: | 14 Sep 2001 at 14:43:01 |
Subject: | [amiga-c] Re: Pointers in tables |
On 14-Sep-01, Lee Atkins wrote:
> Hi,
> I have a small coding question that I hope someone can help me with.
> The situation is this.. I have a large structure that constantly
> changes with development and within this structure are pointers to
> other structures. I need a way to be able to store the 'position' of
> a certain value in my structure so I can look it up in a table.. for
> example..
> An entry in the table would be set up like:
> { "money", structure->substructure->money },
> Then a function would be needed that could manipulate the required
> value when passed an instance of 'structure' and the string "money".
> So what I really want to know is how to put the references to the
> pointers in the table so they can be used with any instance of
> 'structure'. and how to get them out again.
> I hope I've explained it well enough :p
> Ash
Because the data you need to point to in your structure needs
to be a constant to define a static structure from, then I assume
your "structure->substructure->money" is also a constant,
if so, this will work. (above)
However, if you build the structures dynamically so that your
example is created by a dynamic linking or something,
then you will need to actively initialize the value at run time.
eg:
struct mystuff {
byte *name;
struct money *money;
}
You will need to have a pointer to your structure list like this:
struct mystuff MY;
}
MY.name = "money";
MY.money = structure->substructure->money;
If your mystuff is allocated dynamically & you only have a pointer
to it from something like AllocMem() then....
MY = (struct mystuff *) AllocMem(sizeof(struct mystuff), MEMF_PUBLIC);
MY->name = "money";
MY->money = structure->substructure->money;
because you cannot auto-initialize a non-constant at compile time.....
Hope this helps..........
Regards
Colin Wenzel. 157 Brisbane Road,
Mooloolaba, Queensland, Australia. 4557.
PHONE: (07) 5444 5445
EMAIL: colstv@yahoo.com.au
EMAIL2: colinwenzel@yahoo.com
URL: http://www.hotkey.net.au/~colstv/
AMIGA: 4000T, 68060/50, 150Mb RAM,
OS 3.9, Spectrum Gfx Card + P96.
Need an Image Generator For CATV ??
http://connect.to/products
________________________________________
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get VeriSign's FREE GUIDE: "Securing Your Web Site for Business." Learn about using SSL for serious online security. Click Here!
http://us.click.yahoo.com/LgMkJD/I56CAA/yigFAA/dpFolB/TM
---------------------------------------------------------------------~->
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/