This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/MSP432P401R: Pointer memory allocation/ memory address clashes.

Part Number: MSP432P401R

Tool/software: TI C/C++ Compiler

Hi

First post on this forum. Hope i've put this in the right place but to be honest im not fully sure of the root to my problem.

A majority of the product is under NDA so forgive me for being restrained with what I post here. I'd just like to see if anyone has any suggestions before i go as far as writing code to be internet suitable.

Im having an issue with where the my compiler is saving variables.

I'm trying to take a pointer as an argument, this will point to a location where 32, 32bit integers will be stored representing some data of interest. 

The purpose of the function is to format the data, simply construct a local array with the "data of interest" in the middle, an address at the beginning and a CRC at the end. Then return a pointer to the location of the new full array (which should be in a different location to the pointer passed to the function). Ready to be sent off to another device.

The issue im having is that when I enter the function as the arguments are written to the memory, I can clearly see in the memory browser, the last few bytes of the data referenced by the pointer passed in the argument being overwritten.

To represent this:

Before entering function:

Address: 0x000000 (in reality it is stored somewhere in the stack i believe): 1 2 3 4 5 6 7 8 9 ....*dataofinterest*.......32

i then enter the function and upon the debugger passing the opening bracket:

Address: 0x000000: 1 2 3 4 5  6 7 8.....26 27 28 29 30 *pointervalue* 48 03

Now *pointervalue is actually the value of the pointer argument itself while 48 & 3 are the other two arguments passed to the function.

Interestingly the memory location of the three arguments seems to remain constant. But because the data of interest is a MAXIMUM of 32 integers the data of interest does not always go as far as the address of the arguments, for example if the pointer i passed the function referred to a location with 29 pieces of data following it. The data would not be over written when the arguments are initialised upon entering the function.

Any pointers would be appreciated. Any questions, fire away. Really i can't post any code up here but i think i need a deeper understanding of the way the compiler allocates addresses and i need a way of essentially saying "DONT PUT ANYTHING IN THESE 32 LOCATIONS the information following this pointer is X length"

Many thanks

Sean