rtel wrote on Friday, January 02, 2015:
It has always been done this way, and is especially important on devices which only have a few K of RAM. I think the original Cortex-M ports were created on devices with 2K or RAM, in which case it was extremely important to re-use all the RAM that was not intended to be used after the scheduler has started.
Once the scheduler has started main() no longer exists. There is no way back to it and no way of [directly] referencing memory on its stack [which is a compiler controlled construct], so I would turn your argument around and say it is dangerous to try and use resources that were allocated to it, and wasteful to leave resources allocated to something which is in effect orphaned. I don’t see this as being any different to attempting to access something that was on the stack of a task after the task has been deleted.
After the scheduler has started only the tasks and interrupts exist, and they are allocated stacks by the scheduler. If you want memory to be globally or file scope accessible please allocate it globally or file scope.
Regards.