Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Tue Nov 23, 2021 2:32 am |
|
|
Basically standard C.
The function lines you have at the top, are function 'prototypes'. If they
actually contain code, then they are function definitions. In C, you must
have either a prototype or a definition before you access a function. If you
have your definitions before the main, you do not need to have prototypes
at all. So it is common to have a .h file containing the prototypes, load
this before the main, and then have the actual definition afterwards.
The advantage of this is then that the main becomes close to the top
of the program, rather that low down after the definitions. More
important, when you have many thousands of definitions, and some of
these are large....
Now on variables, ones declared 'at the beginning of the program(assuming
this is outside of any function), become 'global' variables. Accessible
for all functions, and holding their values when functions are exited.
Ones declared at the start of a function, are local variables to that function.
They don't actually 'exist' when the function exits (unless declared as
'static'). Any values in them can/will be overwritten when you are out
of the function. The memory they use can/will be re-used in other functions.
Advantage of these is they can't get written to by any other code, and
they save RAM. Downside is they need to be initialised each time the
function is called.
Generally only declare things as global, when they need to be accessed
from multiple locations. Keep these as rare as you can. |
|