Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ SMAUG
➜ SMAUG coding
➜ What's the difference...
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Ithildin
USA (262 posts) Bio
|
| Date
| Thu 02 Dec 2004 05:15 AM (UTC) |
| Message
| What's the difference between:
skill_table[sn]->spell_level
and
skill_table[sn].spell_level | | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #1 on Thu 02 Dec 2004 05:39 AM (UTC) |
| Message
| Well, only one of them is valid, depending on what type of thing you're storing.
First things first...
skill_table[sn]
This is equivalent to:
*(skill_table+sn)
In other words, take the address skill_table, move 'sn' elements forward, and get that value. This is what array indexing really is.
Let us call the result of this operation "s", for simplicity.
Now, for:
s.bla
and
s->bla
s.bla means that s is in fact a structure, and so we can directly access the 'bla' member.
s->bla means that s is a pointer to a structure, so we must first dereference (follow) the pointer, and then do the normal structure retrieval to get the 'bla' member.
If skill_table is an array of pointers to structs, you must use s->bla. If skill_table is an array of structs, you must use s.bla.
Array of pointers to structs:
struct foo { ... };
foo* * myArray;
Array of structs:
foo * myArray;
Note that an array is in fact just a pointer that happens to point to a contiguous block. But, for all intents and purposes, a pointer to an array is the same thing as a pointer to a single element. (This is why strings in C are arrays and also char*, remember.)
Does this answer your question? |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Ithildin
USA (262 posts) Bio
|
| Date
| Reply #2 on Thu 02 Dec 2004 06:38 AM (UTC) |
| Message
| Yes, that helps out heaps.
Thanks for the help. | | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
13,067 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top