This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: why is this result ?


On Fri, Jan 18, 2013 at 01:46:22PM +0000, Andrew Haley wrote:
> On 01/18/2013 03:50 AM, horseriver wrote:
> > hi:
> >   I am doing a test for c++;
> > 
> >   here is my code:  
> > 
> > #include <stdio.h>
> > class A
> > {};
> > 
> > class B
> > {
> > public:
> >   B(){};
> >   ~B(){};
> > };
> > 
> > int main()
> > {
> >   
> >   printf("size of A is %d \n",sizeof(A));
> >   //printf("size of B is %d \n",sizeof(B));
> > }
> > 
> > output is   "size of A is 1 " ,I can not understand this result ,
> >  there is no data in class A ,why here its size is 1?
> 
> Because it's not possible to have an object with nonzero size.  The
> address of every object must be unique, so they have to be separated by
> one byte anyway.

  thanks!
  Here I do not define a object of type A ,just do sizeof operation to a A struct ,not a specified object.
  So if I defined A a , does  sizeof(a) have the same mean with sizeof(A)  ? 
  what does the sizeof operator essentially?
> 
> Andrew.
> 
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]