[LCP]struct size - Empty class size

ritesh kala mast_brat at flashmail.com
Sun Aug 26 17:06:35 UTC 2001


If the size would be 0 then creating an array of any number of such structs
would also result in size 0 and all of them would have the same address.
For example:
empty a[100] would result in a[0] and a[1] to have the same address. 
                                -Ritesh Kala
                                
----- Original Message ----- 
From: sasidhar p 
To: linuxcprogramming at lists.linux.org.au 
Sent: Tuesday, August 21, 2001 9:50 AM
Subject: Re: [LCP]struct size - Empty class size






This discussion about struct size is remiding me of one question I had...
What is the size of an emply class...

#include <iostream.h>
class empty
{
};

main()
{
    cout << "The size of empty class is " << sizeof(empty);
}


Out put:
--------

The size of empty class is 1

Can somebody explain me this behaviour....



>From: Keith Schincke 
>Reply-To: linuxcprogramming at lists.linux.org.au 
>To: 
>Subject: Re: [LCP]struct size 
>Date: Sat, 18 Aug 2001 15:04:04 -0400 (EDT) 
> 
> 
>I think the answer is: Word alignment. The ammount of alignment depends on

>the platforam I think. The details are pretty interesting if you can find them.

> 
>On Sat, 18 Aug 2001, Srinath Thiruvengadam wrote: 
> 
> > hello all, 
> > 
> > please see this code 
> > 
> > struct somestruct 
> > { 
> > int a; 
> > char b; 
> > char c; 
> > }stvar; 
> > 
> > int main() 
> > { 
> > printf("%d",sizeof(stvar)); 
> > } 
> > 
> > the o/p is 8. i was expecting 6 as 'a' occupies 4 bytest and 'b','c' 
> > one byte each ! how is it 8 ?? 
> > 
> > Thanks, 
> > Srinath 
> > 
> 
>-- 
>Keith Schincke My dawg is always with me. 
>Jacksonville, Fl 00 Spool - Wild at Heart 
>http://www.unf.edu/~kschin Email: kschin at unf.edu 
>++The opinions in my email are mine only and are not those of my employer++

> 
> | | | | | 
>-( -( -O_O- )- )- Vibrating Cunning Pike 
> 
> 
> 
>_______________________________________________ 
>This is the Linux C Programming List 
>: http://lists.linux.org.au/listinfo/linuxcprogramming List 


______________________________________________________
Get Your FREE FlashMail Address now at http://www.flashmail.com
It's Free, Easy, & Fun !!!



More information about the linuxCprogramming mailing list