There are two volatile variables:
volatile uint32_t a; volatile uint32_t b; They are declared as volatile, because they can change both in the main program and in the interrupt handler, and devices on the system bus (such as DMA). If both variables participate in the same expression, for example:
uint32_t c = a + b; then the compiler issues a warning. Order of volatile access is undefined in this statement . As I understand it, this means that it is not known which variable will be loaded into the general purpose register first, and it is possible that the a variable is loaded into the register, the interrupt has been triggered, the variable has changed, and the main program continues to work with the old value. Some sources recommend in such situations to break the expression into parts, for example:
uint32_t c = a; c += b; but in my opinion, this is how we only shut up the compiler, and not eliminate the cause of the problem.
And now the actual question. In the program, interrupt handlers constantly periodically change volatile variables, while the main program performs mathematical transformations. As soon as the new value of the variable has come, the old is no longer interesting. Is it possible to ignore the compiler warning in this case? Does this warning have other sources that I don’t guess?