aligned attribute issue

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

aligned attribute issue

1,144件の閲覧回数
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 返答(返信)

1,000件の閲覧回数
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 件の賞賛
返信

1,000件の閲覧回数
cencongsu
Contributor I

So I guess the document description is wrong.

0 件の賞賛
返信