What is padding in C?
All modern CPUs expect that the fundamental types — int’s, float’s and long’s — are stored in the memory at their natural boundary; typically, at addresses that are multiples of their length. Some CPU work efficiently if the memory is properly aligned, and some can work in either case.
For the [...]
Archive for the ‘Structures, Unions & Bitfields’ Category
Structure padding
Unions in C++
Default access to a union is public, it can contain member functions and member data.
Other than that there are some more specialties for unions in C++.
It can’t have a static data members or a member of reference type.
It can’t have virtual functions.
It can’t be used as a base class nor it can have [...]
Posted in Structures, Unions & Bitfields
C Structure Padding
to access a structure member fastly, structure need to be padded
Padding will be done for each and every member, if required, not for the entire structure
Alignment : data storing boundary address starts at aligned address
Examples:
Size of int = 4 bytes
size of char = 1byte
alignment 64 bit (4 bytes)
Struct
{
int a ;
char [...]
Posted in Uncategorized