int *pointer = (int *) na_peripheral;
int read_back;
...
*pointer = 49;
read_back = *pointer;
With a compiler optimization level of -o2 (the default), this program
will write a value of 49 to the peripheral. However, when read_back is
set to the value of the pointer, it will be loaded with the value that was
just written to the peripheral, which is still stored in a Nios core internal
register. This may be acceptable in some circumstances, but it can cause problems if
the peripheral is updated externally at the same time as the read. To ensure
that the Nios core reads the correct value from the peripheral, the pointer
should be declared as follows:
volatile int *pointer = (int *) na_peripheral;
This will ensure that Nios asserted the chip-select and read-enable signals for the desired peripheral.