I need to modify the ordering of my C++ class members. For example:
class B {
public:
int i;
int j;
int k;
...
};
becomes
class B {
public:
int j;
int k;
int i;
...
};
The problem is there are weird codes in my large code bases that depend on relative location of the class members. For example some functions would assume address of member j is smaller than that of member k.
Is there any CASE tool that can help me to identify any code that read the address of a class member?
I am not aware of any tool that solve your problem, but I would define a class which supports all operators for
inttype and which overloads ampersand operator so that the result of the operator cannot be casted to a pointer. Then I'd use this class instead ofintin your class member definitions and look at places where compiler gives errors.Something like
And then:
This will not help against using
boost::addressoffunction or some dirtyreinterpret_castof a reference, butaddressofis probably never used at all in your project, as well as thereinterpret_cast<char&>trick (who would use it for plain integers?).You should also care about taking an address of the whole object of
Bclass.