Machine-translated by Google. Questions are authored in English.
Top

Discussion

An optimisation must be suppressed for a variable declared volatile because

  • A.its value may change by means the compiler cannot see
  • B.volatile variables cannot be held in machine registers
  • C.the language standard forbids optimising such programs
  • D.volatile variables always occupy more storage than others

Answer: A

Correct answer: its value may change by means the compiler cannot see

A volatile object may be a memory-mapped device register or a location written by another thread or a signal handler, so the compiler’s reasoning about what the program does to it is incomplete. Every read and write must therefore be performed exactly as written, in order, and none may be cached in a register or elided.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.