Tag Archives: padding

Structure padding

Structure padding is done by the compilers and this depends on the architectures. Some architectures cannot access the data which will be stored on the odd addresses or they may find difficult to access it. This is the reason for padding extra bytes.

Padding will be done by compiler to structure’s members and to the structure as a whole also. Compiler pads structure as whole because this allows each member of structure aligned in array of structures

Structure padding example
Struct EX
Char a;
int b;
Short int c;

Due to structure padding this structure size is going to be :

(a[1 byte + padding 3 byte + b[4 byte] + c[2 byte] + 2 byte padding = 12byte ) instead of 7 byte.

Byte padding exists for both classes and structures