搜索
bottom↓
回复: 19

请熟悉IAR的大侠看一下这个警告是什么意思?怎么去掉?谢谢

[复制链接]

出0入0汤圆

发表于 2005-8-11 14:13:44 | 显示全部楼层 |阅读模式
Warning[Pa082]: undefined behavior: the order of volatile accesses is undefined in this statement \Source\SubCPU20050725IAR\Display.c 333



注:编译器版本是4.10

阿莫论坛20周年了!感谢大家的支持与爱护!!

如果天空是黑暗的,那就摸黑生存;
如果发出声音是危险的,那就保持沉默;
如果自觉无力发光,那就蜷伏于牆角。
但是,不要习惯了黑暗就为黑暗辩护;
也不要为自己的苟且而得意;
不要嘲讽那些比自己更勇敢的人。
我们可以卑微如尘土,但不可扭曲如蛆虫。

出10入210汤圆

发表于 2005-8-12 10:20:16 | 显示全部楼层
是有個東西未定義,你再看一下,或把程序貼出來,大家一起編譯試試看。

出0入0汤圆

发表于 2006-9-5 12:02:36 | 显示全部楼层
我也遇到了,情况如下



Warning[Pa082]: undefined behavior: the order of volatile accesses is undefined in this statement E:\IAR Embedded Workbench\oil\c\m16.c 368



出错的一行:

if(index_uart_buf==(num_Tdata+7))

....



可是这两个变量我在前面都定义了,还加了volatile(是不是因为这个呢?)

出0入0汤圆

发表于 2006-9-5 12:25:05 | 显示全部楼层
刚google了一下,有人提出问题如此:(鸟语看不懂)

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

undefined in this statement



der dazugehörige Code aus der ADC ISR:

Mess_S1_ES1_Offset = (ADC12MEM0 + ADC12MEM2 + ADC12MEM4 +

ADC12MEM6)/4;



回答:

  temp = ADC12MEM0;

  temp += ADC12MEM2;

  temp += ADC12MEM4;

  temp += ADC12MEM6;

  Mess_..Offset = temp / 4;



于是,我改了那个写法

uchar temp;

temp=num_Tdata+7;



if(index_uart_buf==temp)

.....

警告消失

看来iar 的c 比较严格,呵呵

出0入0汤圆

发表于 2006-9-5 13:54:02 | 显示全部楼层
与到过,这个好像在同一个语句中使用2个以上volatile类型变量久会出现

期待解决方法

3楼:不是鸟语,德语

出0入0汤圆

发表于 2006-9-5 14:19:17 | 显示全部楼层
这个好像在同一个语句中使用2个以上volatile类型变量久会出现



真如此的话可就麻烦了,每次都用一个temp?

出0入31汤圆

发表于 2009-8-28 08:40:52 | 显示全部楼层
Warning[Pa082]: undefined behavior: the order of volatile accesses is undefined in this statement
EW targets: All
EW component: C/C++ compiler
Keywords: C code, keywords, SFR, UART
Last update: January 14, 2009

Background
The warning [Pa082] is issued if 2 (or more) of the variables in a C-statment are volatile. The message text "...order of volatile accesses is undefined..." is the central information, i.e. the compiler (following the ANSII standard) can access the variables in an order that is not defined.

Is this a problem , or not...
...well that depends on your application.
Volatile is (typically) used for variables that are accessed from several threads in the application, and for Special Function Register that are the connection in/out of the chip. So you must study the volatile variables that are present in this C-statement and from the usage of these volatile variables decide if you must make a change or not.

How to change
The change is to break up the C-statement, so that each new C-statement holds only one access to a volatile variable.
In this small example the variables internalChannelSelect and ADC are volatile. If so the following C-source will issue the "Warning[Pa082]".

intAnalogSample[internalChannelSelect] = ADC[internalChannelSelect] ;

Then the following change will make the C-source predictable.

i = internalChannelSelect;
k = ADC;
intAnalogSample = k;

出0入0汤圆

发表于 2010-3-19 16:45:27 | 显示全部楼层
今天我使用它的例子的代码重新建工程编译时也遇到了这个问题,但它用这代码的工程竟不告警,最后发现它的例子是在项目的选项的编译选项的对话框选项里注掉了,所以没有告警。
(原文件名:iar.png)

出0入0汤圆

发表于 2010-5-25 22:23:25 | 显示全部楼层
mark

出0入0汤圆

发表于 2011-3-7 17:48:21 | 显示全部楼层
回复【7楼】hassim 彗 星
-----------------------------------------------------------------------

谢谢大侠

出0入0汤圆

发表于 2011-4-3 10:42:44 | 显示全部楼层
是不是把别人的代码直接移植过来,然后没有分析代码的作用,出现错误不知道怎么改? 先理解代码,然后思考不同编译器之间的差别。

出0入0汤圆

发表于 2011-6-29 10:05:45 | 显示全部楼层
谢谢七楼大侠!

出0入0汤圆

发表于 2011-10-17 22:09:47 | 显示全部楼层
关注,V3.5.0的库,在IAR5.40下编译提示Warning[Pa082]: undefined behavior: the order of volatile accesses is undefined  F:\arm\Cortex-M3\固件库\STM32F10x_StdPeriph_Lib_V3.5.0\Utilities\STM32_EVAL\STM32100B_EVAL\stm32100b_eval_cec.c 568

出0入0汤圆

发表于 2012-8-30 13:41:35 | 显示全部楼层
8楼说的对啊

出0入0汤圆

发表于 2012-8-30 13:43:10 | 显示全部楼层
7楼的更对 赞!

出0入0汤圆

发表于 2012-8-30 14:52:21 | 显示全部楼层
: the order of volatile accesses
volatile变量访问的先后顺序
很重要,先访问谁,后访问谁,结果有可能不一样

出0入0汤圆

发表于 2012-12-18 05:06:58 | 显示全部楼层
freertos的项目把这个警告给屏蔽了....

出0入0汤圆

发表于 2013-9-19 09:59:21 | 显示全部楼层
解决办法就是用中间变量,先将一个 volatile 的值赋给中间变量,再用中间变量和另一个 volatile 变量一起使用。例如,
  1. intAnalogSample[internalChannelSelect] = ADC[internalChannelSelect]
复制代码
这句,internalChannelSelect 和 ADC 都是 volatile 变量(即会在多个线程、中断中使用的),那就先弄个中间变量 i 来解决这个问题:
  1. int i;
  2. i = internalChannelSelect;
  3. intAnalogSample[i] = ADC[i];
复制代码
官方的例子里面用了 2 个中间变量,但是我测试下来(场景和官方例子略有不同),像上面那个样子,用一个就够了。

出0入0汤圆

发表于 2013-9-19 21:12:26 来自手机 | 显示全部楼层
路过,学习学习

出0入0汤圆

发表于 2013-9-19 22:16:40 | 显示全部楼层
好像以前也遇到过,运行没问题,没管它
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-9-27 06:40

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表