On 10/15/2010 10:24 PM, NWhiteford wrote:
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
Check out the packed attribute. http://gcc.gnu.org/onlinedocs/gcc-3.2.3/gcc/Type-Attributes.html Regards, JT