|
-
May 26th, 2011, 10:31 PM
#1
sizeof() class with empty base class
Hello all,
I'm attempting to write some portable code between VC++ and GCC. However, GCC is generating something different and unusable for me without fundamental changes to what I want to do. I have the following hierarchy:
Code:
class Base
{
// helper functions here
};
class Vector4 : public Base
{
float x, y, z, w;
};
class Matrix4x4 : public Base
{
Vector4 rows[4];
};
int main()
{
printf( "sizeof( Matrix4 ) = %i\n", (int)sizeof( Matrix4x4 ) );
return 0;
}
VC++ outputs 64.
GCC outputs 68.
I've tried GCC versions 4.3.4 and 4.5.2, and experimental 4.6.1 and 4.7.0 and they all produce 68.
At first glance you'd think the correct output is 64, but I could be missing some loop-hole rule in the C++ standard that allows GCC to inflate the size of the class in such a way.
Removing the base class in either 'Vector4' or 'Matrix4x4' fixes the problem. However, I plan on adding helper functions to 'Base' class that I want accessible from both the child classes. And 'Base' will remain empty of member variables.
Do you all think this is correct behavior or should I post a GCC bug to their database? Or am SoL because the C++ standard doesn't care.
Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|