The order of volatile accesses is undefined in this statement

Technical Note 99411

Arkitekturer:

All

Komponent:

compiler

Uppdaterad:

2018-01-05 11:33

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.

 

Det här innehållet finns tyvärr inte på svenska.

Vår webbplats finns främst på vårt koncernspråk engelska, förutom det innehåll för investerare som vi är lagstadgade att kommunicera på svenska. Vi rekommenderar att du besöker vår globala webbplats på engelska för att få en bättre upplevelse.

Vi stöder inte längre Internet Explorer. För att få bästa möjliga upplevelse av iar.com rekommenderar vi att du uppgraderar till en modern webbläsare som Chrome eller Edge.