A timer in a function

Here you don't need to say false, static variables get initialised.

But this

bool xInit; 

  if (xInit== 0)
  {

is very asking for trouble. It invokes undefined behaviour, which goes way beyond what you might think, that the variable would necessarily have one, or the other, value.

How I know - learned the hard way


a7