benny1111 wrote on Friday, December 14, 2018:
Hi,
I’m currently in the process of refactoring and optimising some code. I have a questing regarding how the compiler (with optimisations enabled) will see the flow of an application and the initialisation of variables. In the following example, is the compiler aware of the flow from main -> Init task -> Task A? In a tradational bare metal application, a call to the function allows the compiler to be aware that x is changed or used beforehand. Is the function pointer to Task A used in xTaskCreate from the init task essentially telling the compiler the same thing? - That is that x is used/changed before A is executed. In this scenario is there any way the compiler could think that x isn’t ever initialised and remove it? x shouldn’t need to be volatile in this scenario.
Main:
Start Init task
Start scheduler
Init task:
static var x;
Does some stuff
Initialises x
Starts Task A passing a pointer to x
Kills self
Task A:
Loops performing actions and reading parts of var x
Cheers,
Ben