From: eplmst AT lu DOT erisoft DOT se (Martin Stromberg) Newsgroups: alt.comp.lang.learn.c-c++,comp.lang.c++,comp.os.msdos.djgpp Subject: Re: Holes in structure Followup-To: alt.comp.lang.learn.c-c++,comp.lang.c++,comp.os.msdos.djgpp Date: 6 Nov 2001 13:03:57 GMT Organization: Ericsson Erisoft AB, Sweden Lines: 69 Message-ID: <9s8n3t$t2b$1@antares.lu.erisoft.se> References: <3BE7D280 DOT C1732E58 AT bigfoot DOT com> NNTP-Posting-Host: lws256.lu.erisoft.se X-Newsreader: TIN [version 1.2 PL2] To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Alex Vinokur (alexvn AT bigfoot DOT com) wrote: : =============================================================== : Windows98 : gpp : GNU C++ version 2.95.3 20010315/djgpp (release) (djgpp) : compiled by GNU C version 2.95.3 20010315/djgpp (release). : =============================================================== : //----------- : struct type1 : { : long item1; : char item2; : short item3; : char item4; : long item5; : long item6; : int item7; : short item8; : short item9; : char item10; : char item11; : long item12; : float item13; : double item14; : char item15; : }; : ######################################################### : ############### Running (log file) : BEGIN ############## : %a.exe : type1.item1 (long) -> Address = 0 : sizeof = 4 : No hole : type1.item2 (char) -> Address = 4 : sizeof = 1 : No hole : type1.item3 (short) -> Address = 6 : sizeof = 2 : Hole = 1 (before : item) : type1.item4 (char) -> Address = 8 : sizeof = 1 : No hole : type1.item5 (long) -> Address = 12 : sizeof = 4 : Hole = 3 (before : item) : type1.item6 (long) -> Address = 16 : sizeof = 4 : No hole : type1.item7 (int) -> Address = 20 : sizeof = 4 : No hole : type1.item8 (short) -> Address = 24 : sizeof = 2 : No hole : type1.item9 (short) -> Address = 26 : sizeof = 2 : No hole : type1.item10 (char) -> Address = 28 : sizeof = 1 : No hole : type1.item11 (char) -> Address = 29 : sizeof = 1 : No hole : type1.item12 (long) -> Address = 32 : sizeof = 4 : Hole = 2 (before : item) : type1.item13 (float) -> Address = 36 : sizeof = 4 : No hole : type1.item14 (double) -> Address = 40 : sizeof = 8 : No hole : type1.item15 (char) -> Address = 48 : sizeof = 1 : No hole : Struct type1 : : sizeof = 52 : All items sum = 43 : Diff (52 - 43) = 9 : All holes sum = 6 : 2. struct type1 : : Why is not 'Diff' (between 'sizeof' and 'All items sum') : equal 'All holes sum' ? : Note. 'Diff' = 9, 'All holes sum' = 6. : Where has 3 bytes ('Diff' - 'All holes sum') gone? It's padding after item15 I guess. Right, MartinS