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" IS VERY C0NFUSING

I AM NOT UNDERSTANDING THE SITUATION WHEN SHOULD I USE "VOLATILE" WITH VARIABLES ???

Parents
  • Another thing: how can the values of those variables be observed? They can only be observed through the actions of that same program.

    This argument, essentially a subset of the "as-if" rule, holds for normal variables, but not for volatile-qualified ones. Forbidding application of the as-if rule is exactly what volatile is about. Following your line of reasoning, volatile might as well imply static duration, since it doesn't have any effect on automatic variables.

    Also note C99 5.1.2.3: writes to volatile objects are side-effects, and as such they have to be completed before the next sequence point. I rather much doubt that the seeming loop-hole 6.7.3p6 about implementation-definedness of "access to a volatile object" should be understood to cover writing a value to it. Particularly as it stands after a clause of the pattern "except ... as mentioned previously"

Reply
  • Another thing: how can the values of those variables be observed? They can only be observed through the actions of that same program.

    This argument, essentially a subset of the "as-if" rule, holds for normal variables, but not for volatile-qualified ones. Forbidding application of the as-if rule is exactly what volatile is about. Following your line of reasoning, volatile might as well imply static duration, since it doesn't have any effect on automatic variables.

    Also note C99 5.1.2.3: writes to volatile objects are side-effects, and as such they have to be completed before the next sequence point. I rather much doubt that the seeming loop-hole 6.7.3p6 about implementation-definedness of "access to a volatile object" should be understood to cover writing a value to it. Particularly as it stands after a clause of the pattern "except ... as mentioned previously"

Children