Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!amdahl!pyramid!prls!philabs!phri!bc-cis!john From: john@bc-cis.UUCP (John L. Wynstra) Newsgroups: comp.lang.c Subject: sizeof( _variable_ ) Message-ID: <1264@bc-cis.UUCP> Date: 20 Jul 88 11:59:21 GMT Reply-To: john@bc-cis.UUCP (John L. Wynstra) Distribution: na Organization: Brooklyn College of CUNY, Brooklyn, NY Lines: 30 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.