Beginner Help? (Global vs Static)

I am a Arduino beginner and I have a little C++ experience. My question is why does the Arduino projects book make all variables global?

The const global variables I get because they are used in setup and loop. The thing that confuses me is the use of regular global variables. My understanding is this is a no-no(?). I see why it's done this way but would using static variables be a better idea?

I know how both types of variables work I'm just a little lost as to why the project book is doing this. Is there a reason that is Arduino specific that I'm just not aware of? Thanks!

I kinda figured this might be the case but I was not sure. Thanks!

I reckon static vs global is just a matter of personal taste. They have the same impact on Arduino memory.

I generally use global variables, but then I am probably considered to be a C++ philistine.

...R

It's a well-established coding best practice to limit variable scope to the minimum required. Especially for a large project that you hope to be able to maintain.

Robin2:
I reckon static vs global is just a matter of personal taste. They have the same impact on Arduino memory.

I generally use global variables, but then I am probably considered to be a C++ philistine.

...R

But non-static local variables, living on the stack, don't take up space once the function ends :slight_smile:

Blackfin:
But non-static local variables, living on the stack, don't take up space once the function ends :slight_smile:

Does that have even the slightest relevance to the question of global vs static variables?

Steve

Blackfin:
But non-static local variables, living on the stack, don't take up space once the function ends :slight_smile:

Indeed. But that is not what the question is about.

...R