I have a global variable/buffer defined in a header. I have two source files, a function library (lib.c) and a test bench (tb.c), both include the header.
In the library, I fill the global variable buffer, print the pointer value and print some of the entries of the u8 buffer by iterating the pointer, i.e. [1, 2, 3, 4, 5 etc], with pointer 0xC8004C58 (buffer length = 2144).
Now in the test bench, I grab a pointer to this same global u8 buffer in exactly the same way. Now my interpretation is that the global variable remains in the same place so the pointer to its start should be the same, however instead I get pointer 0xC80054D8. Obviously as the pointer is now different, the returned data is [0, 0, 0, 0, 0 etc].
So: If the the u8 buffer stays in the same place and is globally defined, why are my pointers to this buffer different depending on if I'm in lib.c or tb.c?
I'm creating my buffer in the header using:
static u32 RxBuffer_Data[MAX_DMA_RX_FIFOMODE_WORDS] = { 0 };
I'm creating my pointer in the lib.c file using:
u32 *RxBufferPtr_Data = RxBuffer_Data;
I'm creating my pointer in the tb.c file using:L u32 *RxBufferPtr_Data = RxBuffer_Data; or &RxBuffer_Data. Both of these return the same value, and neither are equal to the pointer that correctly prints out the data of the buffer in the lib.c file.