Re: char data[0]
pete <pfilandr@minds pring.comwrites :
[...]
Interesting idea. Normally, 4-byte alignment is a requirement that
address % 4 == 0. (There isn't really a "%" operator for pointers,
but you get the idea; the standard's definition of alignment,
"requiremen t that objects of a particular type be located on storage
boundaries with addresses that are particular multiples of a byte
address", implies something like this.)
What you're suggesting is that a type's alignment could require
alignment % 4 == 3.
Unfortunately, I think it would make malloc() impossible to implement
correctly.
--
Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
pete <pfilandr@minds pring.comwrites :
[...]
With suitable padding bytes,
a struct with a first member of type char,
could be aligned at any address,
no matter what type the other members were.
>
If you had 4 byte ints and a struct type
{
char X;
int Y;
}
>
you could have
X followed by 3 padding bytes
followed by Y
for a struct alignment where the struct was aligned for type int.
>
If the struct was aligned on the next byte then
X followed by 2 padding bytes
followed by Y
followed by 1 padding byte would work.
>
If the struct was aligned on the byte after that then
X followed by 1 padding byte
followed by Y
followed by 2 padding bytes would work.
>
And if the stuct was aligned on the next byte after that then
X contiguous with Y
followed by 3 padding bytes would work.
a struct with a first member of type char,
could be aligned at any address,
no matter what type the other members were.
>
If you had 4 byte ints and a struct type
{
char X;
int Y;
}
>
you could have
X followed by 3 padding bytes
followed by Y
for a struct alignment where the struct was aligned for type int.
>
If the struct was aligned on the next byte then
X followed by 2 padding bytes
followed by Y
followed by 1 padding byte would work.
>
If the struct was aligned on the byte after that then
X followed by 1 padding byte
followed by Y
followed by 2 padding bytes would work.
>
And if the stuct was aligned on the next byte after that then
X contiguous with Y
followed by 3 padding bytes would work.
address % 4 == 0. (There isn't really a "%" operator for pointers,
but you get the idea; the standard's definition of alignment,
"requiremen t that objects of a particular type be located on storage
boundaries with addresses that are particular multiples of a byte
address", implies something like this.)
What you're suggesting is that a type's alignment could require
alignment % 4 == 3.
Unfortunately, I think it would make malloc() impossible to implement
correctly.
--
Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Comment