我相信我理解linux x86-64 ABI如何使用寄存器和堆栈将参数传递给函数(参见之前的ABI讨论).我感到困惑的是,在函数调用中是否预期保留了哪些寄存器.也就是说,哪些寄存器被保证不被破坏?
关于我构建的类以及它如何通过C++中的运算符重载与内置类型交互,我遇到了一些我不理解的东西.作为我的问题的一个例子,下面是一个(不完整的)复数类:
class complex {
public:
complex(double real=0., double imag=0.) : _real(real), _imag(imag) {;}
~complex() {;}
complex& operator=(const complex &rhs) {
if(this!=&rhs) {
this->_real = rhs._real;
this->_imag = rhs._imag;
}
return *this;
}
complex& operator*=(const complex &rhs) {
this->_real = this->_real * rhs._real + this->_imag * rhs._imag;
this->_imag = this->_real * rhs._imag + this->_imag * rhs._real;
return *this;
}
const complex operator*(const complex &other) const {
complex result = *this;
result *= other;
return result;
}
protected:
double _real;
double _imag; …Run Code Online (Sandbox Code Playgroud)