Issue in accessing structure member

Discussion in 'C' started by priyatendulkar, Jul 19, 2011.

  1. priyatendulkar

    priyatendulkar New Member

    Joined:
    Jun 20, 2011
    Messages:
    20
    Likes Received:
    1
    Trophy Points:
    0
    Hi,

    I have a structure as
    Code:
     
    struct S1ap_SetUpRequest:public  S1ap_MessageType
    {
             bool SupportedTAsPresence;
             unsigned int SupportedTAsCount ;
             //and many other members
     };
     
    
    S1ap_MessageType is my Base message
    struct S1ap_MessageType
    {
    S1ap_ProcedureCode_Enum Procedure_Code;
    S1ap_MessageType_Enum Type_of_Message;
    };


    if I declare a pointer to struct S1ap_SetUpRequest and try to access its members using pointer,
    Some wierd memory corruption is observed,where the address of members of structure changes.

    say for eg:
    S1ap_SetUpRequest * ptr = new S1ap_SetUpRequest ;

    address of (ptr->SupportedTAsPresence) at the time of creation is 8276655

    Later on as the code executes
    address of (ptr->SupportedTAsPresence) at the time of creation is 8276658

    Is this possible ?
     
    Last edited by a moderator: Jul 19, 2011
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    No, it shouldn't be possible. However if you have memory corruption and if something overwrites ptr, then this could happen. Solution is to find the memory corruption and fix it.
     
    priyatendulkar likes this.
  3. priyatendulkar

    priyatendulkar New Member

    Joined:
    Jun 20, 2011
    Messages:
    20
    Likes Received:
    1
    Trophy Points:
    0
    hey!!thanks for the reply..
    However, the issue was related to compiler optimisation to make the structure word align..
    Giving some details about my structure.
    1. It is derieved from base structure
    2. The derieved structure has union defined in the structure itself
    3. The derieved structure was not word aligned

    When the derieved structure was explicitly made word aligned the issue was resolved
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice