Hi,
Could a few people using any of gcc 2.9 ... 2.95.x compile the following in ANSI C++ mode on their machines:
#include <stdio.h> // or cstdio if you prefer...
class Dummy1 {
// should have zero size.
public:
typedef enum {
FOO = 0, BAR
} Test;
};
class Dummy2 {
// should be at least the size of one long int.
private:
long x;
public:
typedef enum {
FOO = 0, BAR
} Test;
};
int main(int argN, char** argV)
{
printf("Size of Dummy1 = %ld\n", sizeof(Dummy1));
printf("Size of Dummy2 = %ld\n", sizeof(Dummy2));
return 0;
}
What do you get as output? I get a strange result in 2.95.3, Dummy1 seems to have a size of 1 byte, Dummy2 has a size of 4 bytes. The evaluation of Dummy2's size seems normal but Dummy1's non-zero size I cannot fathom. Even if a virtual table were wrongly added, I'd expect at least a pointer of four bytes.
On gcc 3.x, sizeof(Dummy1) gives 0, which is rather more what I was expecting for an empty class.
Can anybody reproduce the non zero size of the empty class?