Hi, the volatile attribute is an indication that the variable can change for example on account of an interrupt. With this indication the compiler cannot use a register to store the variable, or do any type of optimization. For example if a volatile variable is not used, the compiler do not remove it, as it could be used by an interrupt bye giammy
volatile attribute
Started by ●December 6, 2004
Reply by ●December 6, 20042004-12-06
giangiammy@yahoo.com (Gianluca Moro) wrote in news:dbacaf5c.0412060744.729db90e@posting.google.com:> the volatile attribute is an indication that the variable can change > for example on account of an interrupt.Volatile is a keyword in C. Or when you create a pointer to a volatile "thing" that is, in fact, memory mapped hardware. If the hardware updates the "thing" and the compiler knows the variable is volatile then things should work as you expect. This is not a requirement of ISO C which specifies the behavior of volatile variables in a very restricted way.> With this indication the compiler cannot use a register to store the > variable, or do any type of optimization.No, it can use a register but it must reload the register with the source location every time you access the volatile variable.> For example if a volatile variable is not used, the compiler do not > remove it, as it could be used by an interruptThat's a consequence of volatile. -- - Mark -> --