Hi all, For some reason, I cannot access the structure members if I use struct pointers.
eg:
typedef struct { int member1; }structure_t;
structure_t structure, *structure_ptr;
int main() { sturcture.member1 = 4; //works structure_ptr -> member1 = 4; //does not work
return 0; }
I am using KEIL MDK 5.23 with TM4C123GH6PM. I am using the debugger to see if the member values are changed or not.
What am I missing?
Thanks, EE
Thanks, So I did not reference correctly :(
did not reference correctly What reference?
I believe structure and pointer are not necessary for you at the moment.
Do you understand why I set it to 8?
Yes, I believe you set structure_ptr -> member1 = 8 to make sure that you have indirectly changed the value of structure.member1 to 8.
Just checked, it is that way.
The problem with my code was that I kept the structure pointer dangling.
There was at least one more problem, this time with your compiler settings. You really should have the warning level set high enough that the compiler will tell you about such silly mistakes before you have to ask about them.
have the warning level set high enough that the compiler will tell you about such silly mistakes
Would you please teach me how to do that? I tried on Keil and CodeBlocks, but no success.
typedef struct { int member1; } structure_t; structure_t structure, *structure_ptr; int main() { structure.member1 = 4; structure_ptr->member1 = 8; return 0; }