This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

volatile

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........

Parents
  • 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.

Reply
  • 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.

Children
No data