I currently have a task running which I’m passing a C++ object that is created within main’s stack but it seems I’m getting some corruption when I’m looking at the data. I don’t get the problem when I declare the object being passed in as static (which I’d expect). The IPC object is being passed by reference and as the main routine never exits due to the vTaskStartScheduler(), therefore the “ipc_handle” object is never destroyed? As stated, everything works when I declare IPC as static.
Which hardware platform are you running on? On Cortex-M platforms, we recover the main stack when the scheduler is started and as a resulted anything created on the main stack is destroyed. The rationale of doing so is that the complete main stack is available to Interrupt Service Routines.
So what you are observing is the expected behavior and as you mentioned, you can fix it by declaring the variable static in which it won’t be created on main stack.
Arghhhh it’s been driving me crazy for the pass few hours. I’m using a STM32F7 chip (cortex m7). Do you happen to have any resources about that you’ve stated, as I want to read into this more, just in-case I come across anything else which could catch me out again.