在利用IAR进行编译的时候,经常会出现
Warning[Pa082]: undefined behavior: the order of volatile accesses is undefined in this statement C:\Users\Administrator\Desktop\IAP_BootLoader\UART\ 38
这种报警。
其实这种报警很简单消除。
他的意思是你报警的这条语句中有两个或两个以上被 volatile 定义过的变量。编译器会认为有问题。
如下:
/*看门狗复位计算*/
void wdt_feed(void)
{
if( (LPC_WWDT->TV) <= (LPC_WWDT->WINDOW))
{
// Do a feed sequence to enable the WWDT.
LPC_WWDT->FEED = 0xAA;
LPC_WWDT->FEED = 0x55;
}
}
这里的TV 和 WINDOW 都是被 volatile 定义的变量。
因此想要消除,只需要将其中一个变量值赋给一个临时变量即可。如下:
/*看门狗复位计算*/
void wdt_feed(void)
{
static uint32_t ret
ret = LPC_WWDT->TV;
if( ret <= (LPC_WWDT->WINDOW))
{
// Do a feed sequence to enable the WWDT.
LPC_WWDT->FEED = 0xAA;
LPC_WWDT->FEED = 0x55;
}
}
这样变会消除这个Warning。