Okay, try this:
class CRegister {
protected:
int bits[8];
CString name;
int reg;
CString bitnames[8];
public:
void setRegNumber(int);
void setBitName(int, const CString &);
void setBitName(int, const unsigned char *);
CRegister(void);
CRegister(int);
CRegister(int, int);
CRegister(const CRegister &);
~CRegister(void);
void setBit(int, int);
int getBit(int) const;
int getRegNumber(void) const;
CString getBitName(int) const;
int setBitByName(const CString &, int);
int setBitByName(const unsigned char *, int);
int getBitByName(const CString &) const;
int getBitByName(const unsigned char *) const;
void writeReg(void) const;
int readReg(void);
void setFromVal(int);
int getVal(void) const;
int setField(int, int, int);
int setField(const CString &, int, int * maxbit = NULL);
int setField(const unsigned char *, int, int * maxbit = NULL);
int getField(int, int) const; // Gets the value of a field
int getField(const CString &, int * maxbit = NULL) const;
int getField(const unsigned char *, int * maxbit = NULL) const;
CString getName(void) const;
void setName(const CString &);
void setName(const unsigned char *);
int isRegister(const CString &) const;
int isRegister(const unsigned char *) const;
CRegister& operator=(int);
int operator |=(int);
int operator |=(const CString &);
int operator |=(const unsigned char *);
int operator &=(int);
int operator &=(const CString &);
int operator &=(const unsigned char *);
int operator ^=(int);
int operator ^=(const CString &);
int operator ^=(const unsigned char *);
int operator==(int) const;
int operator!=(int) const;
};
For my other class, I have:
#include "register.h"
class CChannel
{
protected:
CRegister reg[256];
CRegister normregs[16];
CRegister altregs[16];
....some other declarations, etc....
public:
....some other declarations, etc....
};
Later in the .cpp file I have:
reg[18].setName("Test");
reg[18].setRegNumber(18);
reg[18].setBitName(7, "Test07");
reg[18].setBitName(6, "Test06");
reg[18].setBitName(5, "Test05");
reg[18].setBitName(4, "Test04");
reg[18].setBitName(3, "Test03");
reg[18].setBitName(2, "Test02");
reg[18].setBitName(1, "Test01");
reg[18].setBitName(0, "Test00");
normregs[0].setName("Test");
normregs[0].setRegNumber(18);
normregs[0].setBitName(7, "Test07");
normregs[0].setBitName(6, "Test06");
normregs[0].setBitName(5, "Test05");
normregs[0].setBitName(4, "Test04");
normregs[0].setBitName(3, "Test03");
normregs[0].setBitName(2, "Test02");
normregs[0].setBitName(1, "Test01");
normregs[0].setBitName(0, "Test00");
altregs[0].setName("Alt Test");
altregs[0].setRegNumber(18);
altregs[0].setBitName(7, "AltTest07");
altregs[0].setBitName(6, "AltTest06");
altregs[0].setBitName(5, "AltTest05");
altregs[0].setBitName(4, "AltTest04");
altregs[0].setBitName(3, "AltTest03");
altregs[0].setBitName(2, "AltTest02");
altregs[0].setBitName(1, "AltTest01");
altregs[0].setBitName(0, "AltTest00");
.....
where all 16 elements of altregs[] and normregs[] are initialized.
Later on I do stuff with each array and the reg[] array but that is
much later than where I see an issue. What happens is that when I
look at the objects during the initialization process (by stepping
through the code), I notice that altregs[10].bits[0] has the same
address as normregs[0].bits[0]. The exact overlap point also depends
on where I declare the arrays in my CChannel class header file. Here
is an example: if I change around the declarations in my class to
look like:
class CChannel
{
protected:
CRegister reg[256];
....some other declarations, etc....
CRegister normregs[16];
....some other declarations, etc....
CRegister altregs[16];
public:
....some other declarations, etc....
};
then I get the following from the watch window in VC++6 (excuse the
formatting please):
altregs[0] {...}
+ bits 0x007308b8
+ name {""}
reg 0x00000000
+ bitnames 0x007308e0 {""}
altregs[1] {...}
+ bits 0x00730900
+ name {""}
reg 0x00000000
+ bitnames 0x00730928 {""}
normregs[15] {...}
+ bits 0x007308f8
+ name {""}
reg 0x00000000
+ bitnames 0x00730920 {""}
Notice that altregs[1].bitnames (an 8-element array of CString
objects) is very close in memory to normregs[15].bitnames so that they
will probably overlap somehow.
As this is job related I can't give up too much. Does this help clear
up some of the confusion? If not, let me know here and I will put
more out when I can.
Joel