IAR编译警告:the order of volatile accesses is undefined

来源:互联网 发布:淘宝自制摄影棚 编辑:程序博客网 时间:2024/06/06 18:44

转自:http://www.elecbench.com/?p=358

1.问题描述:
在编译代码时出现以下警告。
Warning[Pa082]: undefined behavior: the order of volatile accesses is undefined in this statement

警告处代码如下:
if ((TAR+CcrCont) > TACCR0)
{
return FALSE;
}

警告的意思大体是说,对 volatile 的访问没有被定义。

2.问题分析:
看到 volatile ,才想起以前看过的关于volatile的资料。由于 TAR 是会随时被硬件改变的,所以在使用TAR时应该先拷贝该值到一个临时变量,然后再使用。
所以代码应该修改如下:
u16 Temp = 0;
Temp = TAR;
if ((Temp+CcrCont) > TACCR0)
{
return FALSE;
}

另外,这个报警还提醒了我,我的有些变量应该加上 volatile 关键字。

原创粉丝点击