Alex Rivera | Logout

What is the meaning of "__attribute__((packed, aligned(4))) "

Asked 2012-08-02T02:59:30.683
189

It is C language.It is written that:

typedef struct __attribute__((packed, aligned(4))) Ball {
    float2 delta;
    float2 position;
    //float3 color;
    float size;
    //int arcID;
    //float arcStr;
} Ball_t;
Ball_t *balls;

Please tell me what is the meaning of it,and how to use this keyword.

Edit
Report

1 Answer

30

The attribute packed means that the compiler will not add padding between fields of the struct. Padding is usually used to make fields aligned to their natural size, because some architectures impose penalties for unaligned access or don't allow it at all.

aligned(4) means that the struct should be aligned to an address that is divisible by 4.

answered 2012-08-02T03:04:45.543

Your Answer