global variables?

Are variables global or local? Or does the languate follow the more universal C++ norms?

Asking becuase I want to know if if I modify a normally defined variable ( global) inside a function, if it needs to be passed back to the main loop or if the variable is modified globally.

thanks

PS, I are total programming newb... Please forgive my (probably obvious) questions that I should probably know already...

If it's defined inside a function, then it's local to that function. If it's defined outside of any function, then it's global.

Do look at the reference section. There is a lot of useful info there, including scope - Arduino Reference.

mdkoskenmaki:
does the languate follow the more universal C++ norms?

The wiring language is essentially C++ with some source manipulation before compilation to automate declaration generation.

So from the point of view of how variable, functions and so on work, you can treat it as C++.

@dxw00d - unless, of course, a variable is declared outside of a function definition with the static qualifier (in which its scope is global only within the file/translation unit in which it appears).

Functions with the static qualifier also have their scope limited to the file/translation unit in which they appear.

If you can, try to avoid the use of global variables. If you have to use globals then use statics to limit the scope to a particular module and then use access methods to get access to static module variables.

If you do need globals then wrap them up in a structure and pass a pointer to that structure to other functions, in this way you are only passing the size of a pointer onto the stack. Avoid referencing globals inside functions, instead pass in the pointer to the structure.

@Morris - True, but the OP did say a 'normally defined' variable, which I took mean 'datatype name;'.

Thanks everyone.