|
1 registered members (3run),
4,353
guests, and 1
spider. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
. vs ->
#148947
08/19/07 07:10
08/19/07 07:10
|
Joined: Oct 2003
Posts: 312 Lüneburg, Germany
Gnometech
OP
Senior Member
|
OP
Senior Member
Joined: Oct 2003
Posts: 312
Lüneburg, Germany
|
Hi all! Ok, this had me confused for a while. I have figured it out but I don't know why it works this way, since the manual states otherwise. Here is the thing: I have defined the following struct. Code:
typedef struct { PANEL* p; var row; var col; } Card;
When I know try to access the panel pointer, I have to do it in a special way. In the next example "card" is an array of card pointers: Code:
(card[i])->p = pan_create("bmap = card_base", 1); // works fine ((card[i])->p).pos_x = 25; // does NOT work, instead it overwrites (card[i])->p ((card[i])->p)->pos_x = 25; // works as intended
So it seems in this case I have to use the -> and not the . to access the structure. However, the manual states: Quote:
In standard C / C++, members of structs are accessed by a dot '.' and members of struct pointers are accessed by an arrow '->'. In lite-C or C-Script the compiler automatically detects whether it's a struct or a struct pointer, and the dot '.' can be used for both.
So, is this a bug? Or was I doing something wrong? Anyway, I am glad this works now, it had me confused for a while. By the way, if I declare a global panel pointer "test" and use this one with test.pos_x etc. everything works.
Gnometech
|
|
|
|