This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Accessing structure pointer members

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

Parents Reply Children
  • 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;
    }