heinbali01 wrote on Thursday, November 19, 2015:
Here is a very rough sketch:
int global_counter; // Always exists, accessible for all tasks
static char name; // Always exists, accessible for all functions in this module
void foo( int var1 )
// "int var1" is a function parameter, accessible for the caller task only
int results[ 20 ]; // A variable on stack, will disappear after returning
static unsigned sum = 0; // A variable static in this function
// the same instance continues to exist
// Do something with results
And please note that [automatic] variables often only exists in registers, because the compiler “optimised them away”. But officially they are all placed on the stack, which is visible for the task only.
The contents of your variables is never saved as a task-context, only the necessary registers are pushed on stack. Just like what would happen if an interrupt handler is being called.
If I were you I’d google for these terms: “automatic variables”, “program stack” or read K&R once again