Padding and packing #10
-
Must read for bmp.h https://www.geeksforgeeks.org/structure-member-alignment-padding-and-data-packing/ @sabyasachi07 @chandrakant100 @HembramBeta777 @Ank1taS @Tushar7-coder |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
EXAMPLE 1struct structure_a {
long l;
int i;
char c;
};
EXAMPLE 2struct structure_b {
int i;
long l;
char c;
};
|
Beta Was this translation helpful? Give feedback.
__attribute__((__packed__))
in bmp.h [line 34 and 58] is used to avoid padded bytes among the attributes of structure.Padding
aligns structure members with default address boundaries by the processor whereaspacking
prevents the processor from doing padding. Padding makes the size of the struct bigger by applying some rules of memory alignment whereas packing provides the actual size of the struct to which each member is rounded off.You can refer to this for more.
EXAMPLE 1