Path: utzoo!utgpu!attcan!uunet!lll-winken!lll-tis!ames!umd5!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: sizeof( _variable_ ) Message-ID: <8253@brl-smoke.ARPA> Date: 29 Jul 88 02:34:46 GMT References: <1264@bc-cis.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Distribution: na Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 18 In article <1264@bc-cis.UUCP> john@bc-cis.UUCP (John L. Wynstra) writes: >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! That's not a bug. The sizeof an object must include any alignment padding. Since you can make arrays of Stuff, the Stuff is padded out to a multiple of 4 bytes (the machine word alignment requirement). I happens that this particular structure didn't really need the padding, but since all structs are treated the same in this regard by the compiler, you got the padding anyway. You shouldn't make assumptions about the padding inside a struct.