S
somenath
Hi All,
I have one question regarding the alignment of pointer returned by
malloc.
In K&R2 page number 186 one union is used to enforce the alignment as
mentioned bellow.
typedef long Align;
union header {
struct {
union header *ptr;
unsigned size;
}s;
Align x;
};
typedef union header Header;
In this author is saying that Align field is never used; it just
forces each header to be aligned on a worst-case boundary.
I am not able to understand how Align field forces the alignment ?
According to my understanding alignment of data means storing the data
in proper address as system needs . For example in some system integer
should be stored such that starting address is divisible by power of
2.
But I am not getting how this kind of requirement is enforced by
'Align' .
Please provide some input on this topic.
Regards,
Somenath
I have one question regarding the alignment of pointer returned by
malloc.
In K&R2 page number 186 one union is used to enforce the alignment as
mentioned bellow.
typedef long Align;
union header {
struct {
union header *ptr;
unsigned size;
}s;
Align x;
};
typedef union header Header;
In this author is saying that Align field is never used; it just
forces each header to be aligned on a worst-case boundary.
I am not able to understand how Align field forces the alignment ?
According to my understanding alignment of data means storing the data
in proper address as system needs . For example in some system integer
should be stored such that starting address is divisible by power of
2.
But I am not getting how this kind of requirement is enforced by
'Align' .
Please provide some input on this topic.
Regards,
Somenath