Is it necessary to use volatile when writing to hardware (say a FIFO) in C or C++. It is easy to confirm from online documentation that volatile is necessary when reading hardware, but what about writing? I am concerned that an optimiser could eliminate a loop to write an array of values to a FIFO, and just write the last entry.