The order of volatile accesses is undefined in this statement
Technical Note 99411
Architectures:
All
Component:
compiler
Updated:
1/5/2018 11:33 AM
Introduction
The message below is issued if two or more variables in a C statement are volatile.
Warning[Pa082]: undefined behavior: the order of volatile accesses is undefined in this statement
The important information in the message is the text ...order of volatile accesses is undefined... That is, the IAR C/C++ Compiler will (because it follows the ISO/ANSI standard) access the variables in an order that is not defined.
Discussion
volatile
is (typically) used for variables that are accessed from several threads in the application and for the Special Function Registers that are the connection in/out of the chip. Study how the volatile
variables in this C statement are used and decide if you must make a change or not.
One way to avoid the warning is to break up the C statement, so that each new C statement holds only one access to a volatile
variable. In following example, the variables internalChannelSelect
and ADC
are volatile and will issue the Warning[Pa082].
This code example will give the [Pa082] warning:
intAnalogSample[internalChannelSelect] = ADC[internalChannelSelect];
The following change will make the C source predictable. Note that the temporary variables are NOT volatile:
int i;
int k;
i = internalChannelSelect;
k = ADC[i];
intAnalogSample[i] = k;
Conclusion
To avoid the warning you can break up the C statement, so that each C statement holds only one access to a volatile
variable.
All product names are trademarks or registered trademarks of their respective owners.