Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!mucs!m1!keving From: keving@r4.uk.ac.man.cs (Kevin Glynn) Newsgroups: comp.lang.c++ Subject: Byte padding question Message-ID: Date: 5 Sep 90 12:46:59 GMT Sender: news@cs.man.ac.uk Distribution: comp Organization: ICL Lines: 78 When building a class hierarchy in C++ we found that some extraneous char's were being inserted into the C structure produced by the AT&T front end. After writing a fairly large test program it was found that these bytes were only being generated (at least in our tests) when an empty class (methods only, no member variables) was the base class. I also noticed that in it's child class the extra byte generated for the empty base class was added as well as a new char array of size 1. In the work our department is doing, this will cause problems in the future and we would like to clear up the reason why this is happening (and even better how to stop it happening!). /********************** Part of the original code ***************************/ class GraphCell { public : void *operator new(size_t size); void *operator new(size_t, int sz); void operator delete(void *cell); }; class Instance : public GraphCell { public : void suspend(InstFn function); void activate(); protected : instance header_state; }; /**************** This was generated by the cfront (v2.0) *******************/ struct GraphCell { /* sizeof GraphCell == 2 */ char __W3__9GraphCell ; }; struct Instance { /* sizeof Instance == 22 */ char __W3__9GraphCell ; char __W4[1]; struct instance header_state__8Instance ; }; /****************************************************************************/ Does anybody know why these char's are added, Kevin Glynn ICL -- keving@r1.cs.man.ac.uk sig? No thanx, I'm trying to give up ... -----------------------------------------------------------------