CW10.2 Structure Packing issues

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

CW10.2 Structure Packing issues

ソリューションへジャンプ
765件の閲覧回数
ignisuti
Contributor IV

Can someone please help me explain why sizeof( EVENT_LOG_t ) returns 8? It should be 6, right?

 

Does this have something to do with the way this structure is packed? How can I fix this?

 

My target MCU is Kinetis K10.

 

typedef struct  {  u32 time;  u8 type;  u8 code;}EVENT_LOG_t;
ラベル(1)
0 件の賞賛
返信
1 解決策
572件の閲覧回数
stanish
NXP Employee
NXP Employee

Hello ignisuti,

 

You are right. This is caused by adding the padding bytes to keep data alignment. 

If you need to get rid of these padding bytes you can add pragma:

 

#pragma pack(1)

 

 

but this might have an impact on speed performance.

 

Stanish

元の投稿で解決策を見る

0 件の賞賛
返信
1 返信
573件の閲覧回数
stanish
NXP Employee
NXP Employee

Hello ignisuti,

 

You are right. This is caused by adding the padding bytes to keep data alignment. 

If you need to get rid of these padding bytes you can add pragma:

 

#pragma pack(1)

 

 

but this might have an impact on speed performance.

 

Stanish

0 件の賞賛
返信