class size

NWhiteford new@sgenomics.org
Fri Oct 15 12:56:00 GMT 2010


Hi all,

I have the following code:

#include <iostream>
#include <stdint.h>

using namespace std;

template<int childcount>
class ChildList {
  public:

    ChildList() {
    }

    int8_t  symbol[childcount];
    int32_t index [childcount];
};

int main() {

  ChildList<2> i;

  // (4*2)+(1*2) = 10
  cout << sizeof(ChildList<2>);

}

The class contains 2 chars and two 32bit ints (which should total 10 bytes).

However sizeof prints 12 on my system (g++ 4.5.1 64bit).

What's using the other 2bytes? Is it an alignment thing? Is there a way to remove this?

My apologies if this is a stupid question.
If there's a good reference for this I'd be interested too.

Many Thanks,

Nav



More information about the Gcc-help mailing list