Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

what is the meaning of key word volatile and where it is use

Status
Not open for further replies.

rameshbabu

Member level 2
Joined
Aug 1, 2007
Messages
46
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,663
c

what is the meaning of key word volatile and where it is used ?
 

banjo

Advanced Member level 2
Joined
Dec 24, 2005
Messages
651
Helped
127
Reputation
254
Reaction score
8
Trophy points
1,298
Activity points
8,070
c

volatile tells the compiler that other processes will modify this variable, so do not optimize it.

For example, lets say the main routine continually tests a variable in a loop waiting for an interrupt routine to change it. If the variable is not labeled volatile, the compiler will optimize out the testing loop as it believes it can predict that the loop will never be true.
 

btbass

Advanced Member level 5
Joined
Jul 20, 2001
Messages
1,897
Helped
438
Reputation
880
Reaction score
287
Trophy points
1,363
Location
Oberon
Activity points
12,861
c

It is used when the variable can be changed outside of the program or function you are in, such as an I/O port or a global variable changed by an interrupt routine.
It forces the compiler to read the variable before using it to stop it optimising it away.
 

jayavardhan

Full Member level 2
Joined
Sep 1, 2006
Messages
126
Helped
3
Reputation
6
Reaction score
0
Trophy points
1,296
Location
India
Activity points
1,851
c

volatile variable can be modiied.

For example, lets say the main routine continually tests a variable in a loop waiting for an interrupt routine to change it. If the variable is not labeled volatile, the compiler will optimize out the testing loop as it believes it can predict that the loop will never be true.
 

jitkasem

Junior Member level 3
Joined
Feb 9, 2006
Messages
26
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,448
Re: c

Volatile mean tell the compiler not to optimized that variable.. This because when we use the variable in the fuction it is always store that variable in the register for accessing speed but when the data must change follow the input all the time. Such as the I/O Map architecture it is recommand that you declare the variable using volatile keyword.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top