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:编译器错误行为?

Guru**** 2540720 points


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

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/871834/ccs-msp430g2553-compiler-misbehavior

器件型号:MSP430G2553

工具/软件:Code Composer Studio

我对 CCS9.2 C/C++编译器发出的汇编代码感到困惑。

在涉及编译器 sizeof ()运算符的简单 C 程序的附加屏幕截图中、可以看到编译器已正确计算

a.包含10个六字节结构的数组的大小(60)

MOV.W #0x003c、0x0002 (R15) 

B.每一结构的规模(6),

MOV.W #0x0006、0x0000 (R15) 
C.和数组中的条目数(10) 
MOV.W #0x000A、R13
MOV.W R13 0x0004 (R15) 


但是、当需要通过调整六字节结构(6)的大小来增加指针时、编译器会将指向结构的指针增加36、

ADD.W #0x0024、R15 

编译器为什么会这样做? 36是从哪里来的?

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

    编译器知道对象结构 ptr 指向的大小、并将其递增6个对象。 所以6*6.