Welcome, Guest. Please login or register.

Author Topic: Weirdness in gcc 2.9x  (Read 1032 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
Weirdness in gcc 2.9x
« on: September 26, 2005, 04:28:45 PM »
Hi,

Could a few people using any of gcc 2.9 ... 2.95.x compile the following in ANSI C++ mode on their machines:

Code: [Select]

#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(&quot;Size of Dummy1 = %ld\n&quot;, sizeof(Dummy1));
  printf(&quot;Size of Dummy2 = %ld\n&quot;, 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?
int p; // A