S
sandeep
Hello Friends ~
In K&R (Kernighan and Richie) section 8.7 we find this
< malloc is aligned properly for the objects that will be stored in it.
Although machines varyfor each machine there is a most restrictive type:
if the most restrictive type can be stored at a
particular address, all other types may be also. >
But is this true according to the C standard?
I will describe a machine. On this machine an object can have any size
and an object of size n bytes must be aligned on a multiple of n (e.g.
chars have any alignment, int32_t must be aligned on a multiple of 4
bytes, etc. ... but also a struct of size 5000 bytes must be aligned on a
multiple of 5000 bytes).
Because malloc must return an address that is good for any alignment, it
can only ever return the address zero. So that's what malloc does - it
either returns address zero or a NUL pointer for all calls.
Isn't what I have described conforming to the standard?
Regards ~
In K&R (Kernighan and Richie) section 8.7 we find this
< malloc is aligned properly for the objects that will be stored in it.
Although machines varyfor each machine there is a most restrictive type:
if the most restrictive type can be stored at a
particular address, all other types may be also. >
But is this true according to the C standard?
I will describe a machine. On this machine an object can have any size
and an object of size n bytes must be aligned on a multiple of n (e.g.
chars have any alignment, int32_t must be aligned on a multiple of 4
bytes, etc. ... but also a struct of size 5000 bytes must be aligned on a
multiple of 5000 bytes).
Because malloc must return an address that is good for any alignment, it
can only ever return the address zero. So that's what malloc does - it
either returns address zero or a NUL pointer for all calls.
Isn't what I have described conforming to the standard?
Regards ~