How to declare the globle variable in embedded C i want to use the same variable in many functions as its value should change whenever i edit the variable.
there is no much difference is normal C and embedded C. They are same.... Only thing is In embedded system we use unsigned and very rarely use signed int or chars.............
we also do make use of volatile keyword to store the content of the variable in case of modification by external event that is not under the control of program.....
remember C alows you to make variables 'global' to a project, i.e. so you can use it in a number of files
e.g. define global variable test in file x.c
Code:
// global variables
int test = 10; // define and initialise test
// functions
int readdata()
{
}
declare test extern in file y.c (and any other files)
Code:
// external global variables
extern int test; // declare test
however, be carful with global variables. If you have too many you can loose track of them and forget where you are modifing them, etc. It is best to pass data between functions as value or reference parameters.