So, except for the first 2 i'm pretty sure those are all wrong. You
should try drawing it out. it really helps. Also, you should probably
read up on unions in the books if you have time. But i'll work it out
for you real quick cuz I know it's kinda the last minute. So b is at 0
and it's one byte long. since q is an array of char's (which are one
byte) it doesn't have to be aligned and starts at 1 with q[0] and goes
on to 10 where there's q[9]. Next you have to put in the union which
will need to be aligned to 4 bytes (cuz it has an int and a pointer)
and thus starts at 12. Union are not like structures, because their
elements share space in memory, therefore x, p, and r[0] all have the
same address which is 12. So r[-2] is at 12-2 which is 10. And r[3]
is at 12+3 which is 15.(also r[5] is at 12+5 which is 17 and thus the
union ends at 18) After that there's a very troublesome short
unsigned int, which you might think is 2 bytes, but I've been looking
into it and I'm pretty sure it's 4, someone correct me if i'm wrong.
So you align that to the 4 bytes and it goes at 20. Next the unsigned
long is also 4 bytes and goes at 24. Then you can put w2 at 28 and
it's only 2 bytes, however f is 8 bytes cuz it's a double and must be
aligned 4 so it goes to 32.
Important things to remember:
In linux alignment:
1 bytes things are not aligned (which is pretty much just char)
2 byte things are aligned to 2 bytes (which is pretty much just plain
shorts)
Anything bigger is aligned to 4 bytes (which is all pointers, ints,
longs, doubles)
And as far as I know, double and long double are the only things over
4 bytes being 8 and 10/12 respectively
(the chart of variable lengths is in the book on page 135, note that
nothing that says long but long double is over 4 bytes... which is
kinda confusing but not hard to remember)