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.

What does volatile mean in C language?

Status
Not open for further replies.

dayal

Member level 3
Joined
Aug 26, 2007
Messages
54
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,629
hai all,

what is mean by volatile and what is the use, can anyone tell me briefly.

Thanks
dayal
 

c language volatile

use the search function:
In short: it's used if a variable or register can change it's value outside a specific program location, e.g. an IO port or a variable which is changed in an ISR.
The keyword "volatile" tells the compiler not to optimize this code, so the variable's or register's value is really determined again. Example:
Code:
volatile int counter;

void TimerInterrupt(void)  // interrupt service routine triggered e.g. by timer interrupt
{
  counter++;
}

void main(void)
{
  counter = 0;
  while(1)
  {
    if (counter == 5) DoSomething(); // without volatile declaration this line wouldn't be processed as counter isn't changed here
  }
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top