Search code examples
clinux-device-driverpadding

how to pack a structure inside a structure


Let me more clear, I want to pad an internal structure how do I do it..? Example-

where struct b is

struct b{
  u_int32_t aa;
  u_int32_t bb;
};

struct c{
  u_int64_t cc;
};

Now, my compiler is doing a padding of 8 byte between the struct b and c in struct d. So, how do i get rid of that?

Hope, it clear now. Can somebody give me a answer?

structure d{

struct b;

struct c; //I want to make this structure a padded one, how to go about it?

struct c;

}

Please, can somebody help me with this.


Solution

  • From the tags, I deduce you're on linux. GCC recognizes the following attribute:

    __attribute__((packed))
    

    which you can write before or after the declaration of the struct to remove the padding.