I have a struct declared and set in memory, I have a global constant pointer to this struct and throughout my program I dereference this pointer to access the different parts of the struct. However, there are times when the pointer memory address changes when dereferenced from a specific function.
My struct
typedef struct configData_t
{
uint8_t version[4];
inputConfig_t inputModuleConfig [MAX_INPUT];
outputConfig_t outputModuleConfig [MAX_OUTPUT];
notificationConfig_t notificationConfig [MAX_NOTIFICATIONS];
functionConfig_t autoFunctionConfig [MAX_FUNCTIONS];
uint16_t Crc16;
} configData_t;
The constant pointer is declared by setting the memory address of the data (externally loaded and outside of the applications memory)
//Pointer points to memory location on uC (data already in memory)
const configData_t* theConfigData = (configData_t*)0x0460000;
To get a notification from the 'notificationConfig' array I dereference 'theConfigData' by [1]:
const notificationConfig_t *pNotificationConfig = theConfigData->notificationConfig + notificationID;
The following occurs when stepping through the code on the uC:
- In function A, get notification from struct by using [1], pointer address is 0x463e18
- In function A call function B, dereference the struct using [1] the address changes to 0x463e2a (This is the wrong memory address, 0x12 difference)
- Function B finishes and returns to A, dereferencing theConfigData again using [1] gives 0x463e18
- Every other function in the program that uses [1] always returns the correct (0x463e18) address.
Function B does not alter 'theConfigData' in any way. In the debuggers memory view, the data in 0x0460000 + sizeOf(configData_t) is not altered in any way.
How is the 'pNotificationConfig' pointer changing address when going from function A to B?