Lets say you have a class (c++) or module (single c file). Then in one of your functions you want to store a copy of a variable and hold its value until the next time the function is called, is it better to have a global (could be private in c++ and not extern'd in c to keep it in the module scope) or make a local static variable?
e.g.:
void some_func_that_does_not_do_anything_useful(int arbVal)
{
static int lastArbVal = 0;
if (arbVal > lastArbVal)
{
lastArbVal = arbVal;
}
}
The reason I would make a static is to keep its scope as limited as possible, but certain things I read suggest you should use globals for this, so now I am confused.
What is best (if any)?, pros/cons?