Re: [ROOT] sizeof BUG ??

From: Radovan CHYTRACEK (Radovan.Chytracek@cern.ch)
Date: Tue Jun 05 2001 - 16:45:22 MEST


Hi,

       what's wrong with that? Look at the following code where the empty
class A has been added. When you run this, you get the same sizeof for
both classes A and B. The reason for that is that the static data member
is common to all instances of the class B and is sitting in the separate
static address space of the executable. That's why it does not contribute
to the size of the class B. It's not a bug.

I'm not a rootcint guru, but I suppose it can generate proper streamers
for such a class.

Radovan

------------------------ cut here --------------------------
class A {
public:
  A();
};

A::A() {;}

class B {
public:
  B();
private:
  static long int a;
};

long int B::a=0;

B::B() {;}

int main(int argc, char **argv)
{
  A a[100];
  printf("sizeof  A=%d a=%d \n",sizeof(A),sizeof(a));
  B b[100];
  printf("sizeof  B=%d b=%d \n",sizeof(B),sizeof(b));
  return 1;
}

------------------------ cut here --------------------------

Mikhail Oukhanov wrote:
> 
> Dear C++Root'ers,
> 
> Have you ever met the thing like this?
> How should it be handled in a streamer?
> Any hint is appreciated.
> 
> Regards, Mikhail Ukhanov.
> 
> ------------------------------------------------
> ukhanov@rampexa:~/mwpc$ cat qq.cxx
> 
> #include <stdio.h>
> 
> class B {
> public:
>   B();
> private:
> static long int a;
> };
> 
> long int B::a=0;
> 
> B::B() {;}
> 
> int main(int argc, char **argv)
> {
>   B b[100];
>   printf("sizeof  B=%d b=%d \n",sizeof(B),sizeof(b));
>   return 1;
> }
> 
> ukhanov@rampexa:~/mwpc$ g++ qq.cxx -o qq
> ukhanov@rampexa:~/mwpc$ ./qq
> 
> sizeof  B=1 b=100
> 
> ukhanov@rampexa:~/mwpc$ g++ -v
> Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.2/specs
> gcc version 2.95.2 20000220 (Debian GNU/Linux)
> 
> ukhanov@rampexa:~/mwpc$ uname -a
> Linux rampexa 2.2.17 #9 Tue Jan 30 17:54:11 MSK 2001 i686 unknown
> -----------------------------------------------




This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:48 MET