sizeof( _variable_ )
John L. Wynstra
john at bc-cis.UUCP
Wed Jul 20 21:59:21 AEST 1988
I recently ran up against this one, and, would like to toss it out to
NetLand. I had coded (on a 3b2 running System V.3) the following,
typedef struct {
char x[10];
char y;
char xx[10];
char yy;
} Stuff;
Stuff z;
Later on in the same code I had a reference to sizeof(z) expecting to get 22
(which is btw what I just now got on the bsd 4.2 vax), but what I got was 24!
"Aha!" said I, "either character data is being aligned to even byte
boundaries [which, with an octal dump, I later proved to myself it wasn't] or
I've discovered a compiler bug". A colleague at work pointed out that, perhaps,
what I'm seeing is that storage is being allocated in units of 4 bytes, but
somehow that just doesn't seem right: I should think that sizeof( _variable_ )
should be the length of the _variable_ not the length of the memory allocated
to it. Ah, well...
So, can anyone out there enlighten me as to what is going on?
--john
PS: As luck would have it I was posting while our news feeder was recieving,
and, try as I might, I have no way of knowing if I was quick enough in my
attempt to cancel the first posting. Sorry if this got out twice.
More information about the Comp.lang.c
mailing list