aligned attribute issue

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

aligned attribute issue

1,142 次查看
cencongsu
Contributor I


From the MCU Kinetis Builds Reference Manual, I see:

146281_146281.pngpastedImage_0.png

 

 

I have a code like:

 

struct ss

{

  char a;

  int b __attribute__ ((aligned(1)));

};

 

I compile it with codewarrior 10.6 and use sizeof() to check the size of this struct, And I found the size is 8, and then I check the address of a and b, found their address still align at 4.

 

But I mean to make b align at 1, so the size of the struct shall be 5.

 

Did I misunderstand something or I miss something?

标签 (1)
0 项奖励
回复
2 回复数

998 次查看
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello cencong,

In the structure ss ,the longest is the  "int b" it  is 4 byte ,

so in the (aligned(x)),  the x minimum should be 4 , 1 is wrong.

If you write 1, it is default use the 4 to calculate .

Hope it hleps


Have a great day,
Alice

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复

998 次查看
cencongsu
Contributor I

So I guess the document description is wrong.

0 项奖励
回复