Bizaare non-constant class sizes.

Andrew Over ajo@acm.org
Thu May 11 21:41:00 GMT 2000


Hi all.

I've spent a large chunk of today trying to track down a bizaare
problem using stock gcc 2.95.2 on intel, and was wondering if anyone
had run across anything similar.

I have a situation in which sizeof(class foo) is 200 bytes in one
source file, whilst the SAME CLASS is only 192 bytes in a second.

This results in great nastiness as in one file :

  bar = new foo();

invokes malloc with an argument of 192, whilst the constructor happily
writes 200 bytes worth of data.

There are no preprocessor directives affecting the composition of
either the class or the base classes, and the command line arguments
are identical for both classes.  Nothing internal to the class is of
anything other than an intrinsic type. Inspection of the preprocessor
output of both files shows that the classes _ARE_ the same.

I've progressively removed optimisation options (originally I was
using -O2 -ffunction-sections -fdata-sections), but that has had no
impact on the problem. 

I cannot see why this would happen, but I guess the next step is to
work out member offsets and figure out exactly where things go weird.

I apologise for not being able to post any intermediate output at the
moment, but I need to get management approval.

Any suggestions will be gratefully received :)

Cheers,
--Andrew


More information about the Gcc-bugs mailing list