Microchip
直播中

李子跃

7年用户 200经验值
私信 关注
[问答]

当优化级别设置为1时,结构成员会被破坏

首先,我使用的是XC16V1.31和MPLAB X V3.65的PIC24FV32 KA302。我有一个奇怪的优化行为,其中只有15个成员的结构只在优化级别设置为1时才使前5个成员消失。这个结构是字符串(char *),后面是一些无符号整数。这是一个刚刚开始出现的新行为,我不确定我能做些什么。我曾试图声明结构不稳定,但似乎没有效果。该变量在结构中的数据甚至未被访问的点上被篡改。我输入一个不相关的函数,中间的结构成员被抹去0。每一次运行时,它的精确点似乎不同,尽管这可能是因为我用优化的代码用ICD3进行调试。除了构建没有优化,还有什么可以尝试的吗?我希望至少有一些大小的优化,因为CODISACACE与应用程序的大小相当小。

以上来自于百度翻译


      以下为原文

    Hi all,

First things first, I'm using a PIC24FV32KA302 with XC16 v1.31 and MPLAB X v3.65.

I'm having a weird optimization behavior where a structure with 15 members is getting the first 5 members wiped out only when Optimization Level is set to 1.  The structure is as string (char*) followed by a number of unsigned integers.

This is a new behavior that just started to crop up, and I'm not sure what I can really do about it.  I've attempted to declare the structure volatile but it seems to have no effect.  The variable is getting clobbered at a point where the data in the structure isn't even being accessed.  I enter an unrelated function, and midway through it the structure members in question get wiped out to 0.  The exact point seems to differ each time I run through it, although this could be since I'm debugging with an ICD3 with optimized code.

Is there anything else I can try other than just building without optimization?  I'd prefer to have at least some size optimization, as codespace is rather slim with the size of this application.

Any advice would be appreciated,

Thanks!



回帖(14)

王璨

2019-1-30 11:16:04
请张贴相关代码!试图分析一些“不知何故”的情况几乎是不可能的。

以上来自于百度翻译


      以下为原文

    Please post the relevant code!
Trying to analyze some situation described "somehow" is next to impossible.
举报

陈晨

2019-1-30 11:24:21
该变量在结构中的数据甚至未被访问的点上被阻塞,这听起来是在其他地方的指针错误,或者是一个缓冲区溢出错误。

以上来自于百度翻译


      以下为原文

    The variable is getting clobbered at a point where the data in the structure isn't even being accessed.
That sounds line a pointer error somewhere else, or a Buffer over run error.
举报

杨叶

2019-1-30 11:40:35
嗨,在大多数情况下,调试一个优化的项目是不可能的……对于你的结构,你是否试图使你的结构中的每个成员都具有易失性?你对结构中成员的顺序有什么假设吗?当做

以上来自于百度翻译


      以下为原文

    Hi,
In most cases debugging an optimized project is impossible...
Regarding your structure, did you try to qualify as volatile each member of your structure ?
Did you make any assumption about the order of the members in the structure ?
Regards
 
举报

王焕树

2019-1-30 11:46:06
…或尝试访问变量时,它不再在范围内?…或者仅仅取决于监视窗口中显示的变量,而这些变量在代码中从未使用过。代码中的bug只在优化启用时才出现,但它们仍然是错误。

以上来自于百度翻译


      以下为原文

    ... or try to access the variable when it is no longer in scope?
... or just depending upon what is shown in the WATCH window for a variable that is never used in your code.
Bugs like that in your code sometimes only show up when optimisation is enabled, but they are still bugs.
 
 
举报

更多回帖

发帖
×
20
完善资料,
赚取积分