cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Newbie
Newbie
3,584 Views
Registered: ‎08-08-2012

Help Using __attribute__ ((__packed__)) Microblaze

Hey guys, 

 

This may seem like a dumb question because there are examples over the web using __attribute__((_packed)), However I am not sure if it is intended to be used the way I am trying to use it since I never get the result I am looking for.  For example

 

Sturct my_sturct{

           short a;

           short b;

}; 

 

Struct __attribute__((_packed_))  size{

           short x;

           short y;

           short z; 

          my_struct c; 

};

 

My thought is that the size of the struct should be packed to 10 bytes or 12 bytes with the 2 extra at the end, however it adds padding between short z and m_sctruc c.  I need them to be pack.. or maybe its the way I call the struct is the problem such as 

 

 I have an array say:  char my_array [12] = {0,1,2,3,4,5,6,7,8,9,10,11};  // total of 12 bytes

 

I want to fill the sturcture using this array

so 

 

size struct_fill;   

 

struct_fill  = *(const size*) my_array;

 

by doing this my structure is filled but is miss alligned when it gets to filling up:

 

short x = 0x01

short y = 0x23

short z = 0x45

my_struct c  =0x89AB

 

when it should be 

my_struct c  =0x6789

 

Im sure its something stupid I'm missing but I am stumped on this problem.. and I know microblaze does not support pragma pack.

 

Thanks for your help in advanced; 

 


 

 

 

 

 

Tags (3)
0 Kudos
2 Replies
Highlighted
Newbie
Newbie
3,572 Views
Registered: ‎08-08-2012

Sorry Typo:
short x = 0x0001
short y = 0x0203
short z = 0x0405
my_struct c =0x08090A0B
0 Kudos
Highlighted
Contributor
Contributor
3,557 Views
Registered: ‎02-27-2008

I cannot tell you what is wrong in your case because your code seems incomplete but I am using Microblaze with packed data and in my case, I redefine my structures with "typedef" and it works.
Your case would be:

typedef struct{
  short a;
  short b;
} my_struct;

typedef struct __attribute__((_packed_)){
  short x;
  short y;
  short z;
  my_struct c;
} size;

0 Kudos