不同的对象指针值及其this指针
基本上,我编写了一个类,其中包含另一个类数组属性,我的意思是:
class MyClass
{
unsigned long long x_;
bool y_;
public:
MyClass & operator=(const MyClass & mc)
{
x_ = mc.x_;
y_ = mc.y_;
return *this;
}
};
class MyOtherClass
{
MyClass myClass_[9];
public:
MyOtherClass & operator=(const MyOtherClass & mc)
{
for (unsigned int i = 0; i < 9; i++)
{
myClass_[i] = mc.myClass_[i];
}
return *this;
}
};
所有这些都在共享库中实现。
我在第二个库中使用第二个类,例如:
void ThridClass::foo( )
{
MyOtherClass c1;
MyOtherClass c2;
c1 = c2;
}
在 xlC_7 的 64 位编译模式下,没有对齐编译指示、没有优化、非虚拟函数等,在 Aix 系统上运行。
这些是我在两个库中使用的编译器选项:
-q64 -bernotok -g -M -qflag=i:w
这些是链接器选项:
-brtl -bernotok -G
当我使用 dbx 调试程序并询问 c1.myClass_[0]
地址时,我得到了一个值。但是,如果我跟踪 MyOtherClass.operator=() 函数内部的执行,我会得到该属性指针的另一个地址。
(dbx) p &c1.myClass_[0]
0x0ffffffffffe6a20
(dbx) s
stopped in operator=(const MyOtherClass &)
(dbx) p &myClass_[0]
0x0ffffffffffe69c0
这个问题在 Linux 上不会出现并且工作正常。
有什么想法吗?
basically, I wrote a class with another class array atributte inside, I mean:
class MyClass
{
unsigned long long x_;
bool y_;
public:
MyClass & operator=(const MyClass & mc)
{
x_ = mc.x_;
y_ = mc.y_;
return *this;
}
};
class MyOtherClass
{
MyClass myClass_[9];
public:
MyOtherClass & operator=(const MyOtherClass & mc)
{
for (unsigned int i = 0; i < 9; i++)
{
myClass_[i] = mc.myClass_[i];
}
return *this;
}
};
all of this implemented in a shared library.
I use second class in a second library like:
void ThridClass::foo( )
{
MyOtherClass c1;
MyOtherClass c2;
c1 = c2;
}
in a 64bit compilation mode with xlC_7, with no alignment pragmas, no optimization, non virtual
functions, etc, running on an Aix system.
These are the compiler options I used in both libraries:
-q64 -bernotok -g -M -qflag=i:w
and these are linker options:
-brtl -bernotok -G
When I debug the program using dbx and ask for c1.myClass_[0]
address I got one value. But, if I strace the execution inside MyOtherClass.operator=()
function, I get another address for this attribute pointer.
(dbx) p &c1.myClass_[0]
0x0ffffffffffe6a20
(dbx) s
stopped in operator=(const MyOtherClass &)
(dbx) p &myClass_[0]
0x0ffffffffffe69c0
This problem doesn't apperar on Linux and works fine.
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需放弃复制赋值和复制构造函数定义 - 隐式编译器生成的定义就足够了。
Just ditch your copy assignment and copy constructor definitions- the implicit compiler-generated ones will be more than sufficient.
在你的operator=中你返回循环内部
In your operator= you return inside the loop