This is the mail archive of the gcc@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]

Question about empty classes


Hi,

I try hard to save memory in my designs, which is why I was
unpleasantly surpriced to find out that egcs (1.1b) assigns
at least 4 bytes to any empty class :/.

For instance:

class empty {
public:
  bool empty(void) { return true; }
  int foobar(int i) { return i; }
};

class A : public empty {
public:
  int i;
};

Gives sizeof(A) == 8

Likewise

class B {
public:
  int i;
  empty x;
};

gives sizeof(B) == 8

:(

Why is this?  Is there a way around this?
Please CC me because I am not subbed to this list (anymore).

-- 
 Carlo Wood  <carlo@runaway.xs4all.nl>


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