I know in general, a struct instance will have the alignment of its widest scalar member. I declared a structure having a member of long double
data type.
struct try
{
char a;
long double b;
};
struct try obj;
When i tried to check sizeof(obj)
it is coming out as 16
. My compiler assumes long double
as 12
bytes. So i am not able to understand how exactly padding is being done here and how alignment is happening in structure. I assumed that alignment will be done on basis of long double
as it is the widest scalar member. So there should be a 11
byte padding for char and the size of structure variable should come out as 24
but output is 16
. So exactly what is happening here ?. I am working on a 64 bit
processor.