Warning[Pa082]: undefined behavior: the order of volatile accesses is undefined in this statement

来源:互联网 发布:新网域名如何绑定空间 编辑:程序博客网 时间:2024/05/21 17:04

Warning[Pa082]: undefined behavior: the order of volatile accesses is undefined in this statement

 

运算符两边都是volatile变量的警告

 

这警告有意义.

用volatile修饰的变量一般不直接参与运算,volatile就以为着这个变量在运算过程中有可能已经改变了

改正方式:

例如:想计算a * b 要这样:

复制代码
volatile unsigned char a;
volatile unsigned char b;

unsigned char x,y;

x = a;
y = b;

return (x * y);
复制代码


建议使用另外一个变量参与计算:

复制代码
volatile char VVV = 9;

char fun()
{
char xxx;
char yyy = 9;

xxx = VVV;
return xxx * yyy
}
复制代码


0 0
原创粉丝点击