We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi, when keyword volatile is used in the C programming...i have studied in one book that this volatile keyword is a directive to the compiler's optimizer that variables declared as volatile will not undergo any optimization by the compiler.......... My question is what type of optimizations the compiler is not allowed to be performed on that variable. i have been learning 8051 microcontroller(Atmel At89c51) C programming. Please little help will be very useful for my interviews.
thanks in advance........
The compiler must not assume that it knows the value of the variable and optimize away reloads, since a volatile variable may change value asynchronously.
in one book that this volatile keyword is a directive to the compiler's optimizer that variables declared as volatile will not undergo any optimization by the compiler.
You're studying from a bad book then. The meaning of volatile is quite a bit more specific than that. The actual meaning is that the compiled code must behave like the abstract machine defined in the C language standard, as far as volatile qualified variables are concerned. Disabling some optimizations is just one of its effects.