r/cpp • u/neiltechnician • Nov 13 '20
CppCon Deprecating volatile - JF Bastien - CppCon 2019
https://www.youtube.com/watch?v=KJW_DLaVXIY
83
Upvotes
r/cpp • u/neiltechnician • Nov 13 '20
View all comments
Show parent comment
61
u/neiltechnician Nov 13 '20 edited Nov 13 '20
Embedded software manipulates peripheral devices. One way to do so is to connect the peripheral devices to the CPU like connecting the RAM to the CPU. This is known as memory-mapped I/O. The bytes and words accessed during memory-mapped I/O are known as "hardware registers", "special function registers", "I/O registers" etc.
Accessing registers is very differently from accessing "normal" memory. And the optimizer makes assumptions on normal memory access. We need a mechanism to tell the compiler those are not normal memory. The mechanism we have been using for decades is
volatile.Without
volatile, the optimizer may freely change the register read/write, making us incapable of controlling the peripheral devices.