Pragma Pack Ignored and __attribute__ ((aligned (2), packaged)); Has no effect

advertisements

I have been trying to look up this problem but have not found a solution that works. My compiler is ignoring #pragma pack(push) #pragma pack(2) and __ attribute __ ((aligned (2), packed)) does not solve problem as well. The stack is 8 byte aligned and want to convert some structures to be 2 byte aligned. -fpack-struct works but it affects all structures.

I would like to use #pragma pack.

I am programming a xilinx microblaze in SDK 13.3 eclipse IDE GCC #4.1.2

I guess I dont understand what is making the compiler ignore the Pragma pack.. I dont want to turn the warnings off I would like to use it.

#pragma pack(push)
#pragma pack(2)
struct _Size_Test
{

  union
  {
    struct{
        int8    x;
        int8    y;
     };
     int16    z;
  };
}Size_Test;
#pragma pack(pop)

sizeof(Size_test) = 4 when it should be 2

adding attribute((aligned(2),packed)) does not work

struct _Size_Test
{

  union
  {
    struct{
        int8    x;
        int8    y;
     };
     int16    z;
  };
}Size_Test _attribute_((aligned(2),packed));


You can use something like this for your struct:

struct __packed__
{
    char* member_one;
    int *member_two;
    ....
} my_struct;

You can also try to suppress the standard alignment by using this:

int *__unaligned my_int_pointer;

Hope this help.

Regards.