incompatible class types
y2bismil@engmail.uwaterloo.ca
y2bismil@engmail.uwaterloo.ca
Thu Nov 13 19:03:00 GMT 2003
Hi all,
This is a bit of a weird one. Basically this is old code that I don't want to
change a lot of it. Someone, someday made some assumptions about class layout
that aren't valid in GCC.
consider these two classes.
*********************************
class C1 {
public:
C1() { initQC() ; }
C1(unsigned q_type) { initQC(q_type) ; }
inline void initQC() ;
inline void initQC(unsigned q_type) ;
private:
struct LINK {
C1 *fwd ,
*bkwd ;
} ;
LINK links[MAX_LINKS] ;
//member functions
};
***********************************
***********************************
class TEVENT {
public:
TEVENT() ;
TEVENT( void *dump_addr ) ; // only used in dump debug build.
virtual ~TEVENT() ;
virtual void event_activate( void ) = 0 ;
//other functions
private:
QC *_fwd ;
QC *_bkwd ;
// other member variables
}
****************************************
class QC is the main class used in function calls, but its done in a funny
manner. All params into such functions are done through void*.
void ADD_TO_Q( void *element)
{
//element is assumed in here to be of type QC
}
But throughout the code, both QC* and TEVENT* are passed into ADD_TO_Q type
functions. (Other variants of TEVENT* also exist, but this is just an example).
This worked fine with the greenhills compiler and the watcom compiler for a long
time. Of course, that doesn't make the code right by any means. Basically the
two types differ by 4 bytes from their first instance of QC *_fwd (one in the
array, one in a direct variable). I am assuming this is due to the virtual
functions in TEVENT leading to a prefix of a pointer to a v-table.
Other classes do derive from TEVENT and do make use of the virtual functions.
My solution to this so far is to write a cast routine from TEVENT to QC and
vice-versa. Going from TEVENT to QC would not be too bad. But going from QC to
TEVENT is going to have to be a hard-coded number (4) correct?
I'm open to any suggestions here.
Thanks,
Yamin
----------------------------------------
This mail sent through www.mywaterloo.ca
More information about the Gcc-help
mailing list