Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to declare the globle variable in emdded c

Status
Not open for further replies.

Sharath411

Member level 1
Joined
Mar 27, 2010
Messages
38
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Bangalore
Activity points
1,529
Hi friends,

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.


Thank You........
 

declare the variable before the main function as similar as in TURBO C

---------- Post added at 06:54 ---------- Previous post was at 06:51 ----------

ex:

char num;

void main
{
}
function1()
{
you can edit the value here
}

function2()
{
you can edit the value here also
}
 
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.
 
yes, define global variable test in file x.c
Code:
     // global variables
     int test[50] = {0};        // define and initialise test
declare test extern in file y.c (and any other files)
Code:
     // external global variables
     extern int test[];        // declare test
similar with structures, etc
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top