編譯器的地址對齊問題

我們看 CanRxMsg


typedef struct
{
? uint32_t StdId;? /* Specifies the standard identifier.
????????????????????? This parameter can be a value between 0 to 0x7FF. */

? uint32_t ExtId;? /* Specifies the extended identifier.
????????????????????? This parameter can be a value between 0 to 0x1FFFFFFF. */

? uint8_t IDE;???? /* Specifies the type of identifier for the message that
????????????????????? will be received. This parameter can be a value of
????????????????????? @ref CAN_identifier_type */

? uint8_t RTR;???? /* Specifies the type of frame for the received message.
????????????????????? This parameter can be a value of
????????????????????? @ref CAN_remote_transmission_request */

? uint8_t DLC;???? /* Specifies the length of the frame that will be received.
????????????????????? This parameter can be a value between 0 to 8 */

? uint8_t Data[8]; /* Contains the data to be received. It ranges from 0 to
????????????????????? 0xFF. */

? uint8_t FMI;???? /* Specifies the index of the filter the message stored in
????????????????????? the mailbox passes through. This parameter can be a
????????????????????? value between 0 to 0xFF */
} CanRxMsg;


Data字段作為一個 uint8_t 數(shù)組,起始地址并未對齊到 DWORD,而是緊跟著 DLC?

您好,數(shù)組類型為uint_8,則按照該類型大小進(jìn)行內(nèi)存對齊,并不是將該數(shù)組作為整體計(jì)算大小進(jìn)行對齊。
您可使用__attribute__((aligned(4))) uint8_t Data[8];控制該成員變量的對齊形式,從而達(dá)到數(shù)組四字節(jié)對齊的效果。


只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频