<html><div style='background-color:'><DIV>
<P><BR><BR></P>This discussion about struct size is remiding me of one question I had...</DIV>
<DIV>What is the size of an emply class...</DIV>
<DIV> </DIV>
<DIV>#include <iostream.h></DIV>
<DIV>class empty</DIV>
<DIV>{</DIV>
<DIV>};</DIV>
<DIV> </DIV>
<DIV>main()</DIV>
<DIV>{</DIV>
<DIV> cout << "The size of empty class is " << sizeof(empty);</DIV>
<DIV>}</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>Out put:</DIV>
<DIV>--------</DIV>
<DIV> </DIV>
<DIV>The size of empty class is 1</DIV>
<DIV> </DIV>
<DIV>Can somebody explain me this behaviour....</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV></DIV>>From: Keith Schincke <KSCHIN@UNF.EDU>
<DIV></DIV>>Reply-To: linuxcprogramming@lists.linux.org.au
<DIV></DIV>>To: <LINUXCPROGRAMMING@LISTS.LINUX.ORG.AU>
<DIV></DIV>>Subject: Re: [LCP]struct size
<DIV></DIV>>Date: Sat, 18 Aug 2001 15:04:04 -0400 (EDT)
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>I think the answer is: Word alignment. The ammount of alignment depends on
<DIV></DIV>>the platforam I think. The details are pretty interesting if you can find them.
<DIV></DIV>>
<DIV></DIV>>On Sat, 18 Aug 2001, Srinath Thiruvengadam wrote:
<DIV></DIV>>
<DIV></DIV>> > hello all,
<DIV></DIV>> >
<DIV></DIV>> > please see this code
<DIV></DIV>> >
<DIV></DIV>> > struct somestruct
<DIV></DIV>> > {
<DIV></DIV>> > int a;
<DIV></DIV>> > char b;
<DIV></DIV>> > char c;
<DIV></DIV>> > }stvar;
<DIV></DIV>> >
<DIV></DIV>> > int main()
<DIV></DIV>> > {
<DIV></DIV>> > printf("%d",sizeof(stvar));
<DIV></DIV>> > }
<DIV></DIV>> >
<DIV></DIV>> > the o/p is 8. i was expecting 6 as 'a' occupies 4 bytest and 'b','c'
<DIV></DIV>> > one byte each ! how is it 8 ??
<DIV></DIV>> >
<DIV></DIV>> > Thanks,
<DIV></DIV>> > Srinath
<DIV></DIV>> >
<DIV></DIV>>
<DIV></DIV>>--
<DIV></DIV>>Keith Schincke My dawg is always with me.
<DIV></DIV>>Jacksonville, Fl 00 Spool - Wild at Heart
<DIV></DIV>>http://www.unf.edu/~kschin Email: kschin@unf.edu
<DIV></DIV>>++The opinions in my email are mine only and are not those of my employer++
<DIV></DIV>>
<DIV></DIV>> | | | | |
<DIV></DIV>>-( -( -O_O- )- )- Vibrating Cunning Pike
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>_______________________________________________
<DIV></DIV>>This is the Linux C Programming List
<DIV></DIV>>: http://lists.linux.org.au/listinfo/linuxcprogramming List
<DIV></DIV></div><br clear=all><hr>Get your FREE download of MSN Explorer at <a href='http://go.msn.com/bql/hmtag_itl_EN.asp'>http://explorer.msn.com</a><br></html>