I know globals are frowned upon however does performance take a hit when you declare your variables inside the main loop? Each time the program loops it has to redeclare the variables vs use ones that already exists.
In small programs on microcontrollers its not so bad to use global variables.
Where to declare your variables is more a matter of scope. If you want the scope to be global, then use a global. If you want the scope limited to loop, then put them in loop.
Each time the program loops it has to redeclare the variables vs use ones that already exists.
Unless the type constructor is particularly onerous (just a stack frame operation for simple integers), this is no big deal, and declaring local variables may mean a better chance of staying in a register whilst in-scope.
What AWOL said, plus...
First of all, write your programs so that they are clear and function correctly. If they are clear, they are more likely to function correctly also.
Then, IF AND ONLY IF you need more performance, you can worry about optimizations at this level.
Thank you all!