Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Issue in accessing structure member (http://www.go4expert.com/forums/issue-accessing-structure-t26319/)

priyatendulkar 19Jul2011 18:25

Issue in accessing structure member

I have a structure as

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 ?

xpi0t0s 20Jul2011 16:37

Re: Issue in accessing structure member
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 22Jul2011 16:08

Re: Issue in accessing structure member
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

All times are GMT +5.5. The time now is 19:48.