aligned attribute issue

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

aligned attribute issue

682 Views
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?

Labels (1)
0 Kudos
Reply
2 Replies

538 Views
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 Kudos
Reply

538 Views
cencongsu
Contributor I

So I guess the document description is wrong.

0 Kudos
Reply