This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] CCS/MSP430G2553:错误的数据对齐(MSP430G2553,CCS v7中)

Guru**** 2535150 points
Other Parts Discussed in Thread: MSP430G2553

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/567865/ccs-msp430g2553-wrong-data-alignment-msp430g2553-in-ccs-v7

部件号:MSP430G2553
主题中讨论的其他部件: MSP-EXP430G2

工具/软件:Code Composer Studio

您好,

我在CCS v中使用结构时遇到了错误的数据对齐7.0。

请提供建议。

提前感谢您的参与。

 

IDE:CCS 7.0 0.0.0042万

MCU:MSP430G2553

Launchpad:MSP-EXP430G2 (版本1.5)

 

[定义以下结构]:

typedef结构

 无符号字符x;

 unsigned char a[16];

} XA;

[声明变量]:

xa y;

无符号*p;

 

[指定以下指令]:

//我要通过指针*p:访问数组y.a[]

p =(unsigned short *)&y.A[0];

*p = 0x0708;

[但是,得到了错误的对齐结果]:  y.x = 0x08  和  y.A[0]= 0x07  !!

 

[其他 说明]:

p =(unsigned short*)&y.a[1];

*p = 0x0708;

[此时间结果正确]:  y.A[1]= 0x08  和  y.A[2]= 0x07。

 

看起来,它是偶数地址匹配的!!!

 

 

谢谢

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    是的,这就是它的工作方式。 取消引用指向内存的指针,如果该指针未与其所指向的类型正确对齐,则会导致出现未定义的行为。 这意味着该代码不是合法的C代码。