Static Variables in functions

michaeln32 wrote on Sunday, August 07, 2016:

If i deine varialbe as ‘Static’ inside a function is it in the global scope or in the stack ?
For example:

void func(void)
static int i = 0;


rtel wrote on Sunday, August 07, 2016:

This is a C question, not a FreeRTOS question.

…and the answer is neither…

as you show it it is a function scope static. That means it retains its
value between calls to the function, so it cannot be on the stack.

It also means the function is not thread safe, as all tasks that call
the function will use the same copy of the variable.