在C++中,函数返回整数或指针是通过eax寄存器进行传递的,理解起来比较简单。
但是返回对象或结构体一直是令人感到困惑的问题。今天我整理了一下,将整个返回过程写下来,以作备用。
还是先通过一个例子来理解这个问题:
首先,定义一个类Vector:
class Vector
{
public:
int x,y;
};
然后定义函数add()对Vector对象进行操作:
Vector add(Vector& a, Vector & b)
{
Vector v;
v.x = a.x + b.x;
v.y = a.y + b.y;
return v;
}
现在的问题是:
如果调用如下语句:
Vector a, b;
Vector c = add(a, b);
请问从a, b传入函数开始,一共创建了多少个对象?
在通常情况下我们会做出如下分析:
1. 在add()函数中创建对象v。
2. 函数返回,创建一个临时变量__temp0,并将v的值拷贝到__temp0中。
3. 最后创建对象c,通过操作符=,将__temp0中的对象拷贝到c中。
但其实,我们会在后面看到,整个过程就只创建了1个对象:c。
为了更清晰的分析整个调用过程,我们为Vector加上默认构造函数和拷贝构造函数,并增加一个静态变量count用于统计构造函数调用次数:
class Vector
{
public:
static int count;
static void init()
{
count = 0;
}
int x,y;
Vector()
{
x = 0;
y = 0;
// For analysis.
count ++;
printf("Default Constructor was called.[0x%08x]\n", this);
}
Vector(const Vector & ref)
{
x = ref.x;
y = ref.y;
// For analysis.
count ++;
printf("Copy Constructor was called.[copy from 0x%08x to 0x%08x].\n", &ref, this);
}
};
int Vector::count = 0;
然后在main()函数中写上调用代码:
Vector a, b;
Vector::init();
printf("\n-- Test add() --\n");
Vector c = add(a, b);
printf("---- Constructors were called %d times. ----\n\n\n", Vector::count);
使用cl编译。
(注:Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86, Microsoft (R) Incremental Linker Version 10.00.40219.01)
完成后,运行程序,得到如下结果:
-- Test add() --
Default Constructor was called.[0x0012fef8]
Copy Constructor was called.[copy from 0x0012fef8 to 0x0012ff60].
---- Constructors were called 2 times. ----
由此可知,在没有优化的情况下,整个调用过程共创建了两个对象:
即:c和__temp0.
整个调用过程伪代码如下:
首先add()函数被编译器看做:
void add(Vector& __result, Vector& a, Vector & b)
{
__result.x = a.x + b.x;
__result.y = a.y + b.y;
return;
}
而调用代码同时被修改为:
Vector a, b;
Vector::init();
printf("\n-- Test add() --\n");
Vector __temp0; // 构造函数.
add(__temp0, a, b);
Vector c(__temp0); // 拷贝构造函数.
printf("---- Constructors were called %d times. ----\n\n\n", Vector::count);
现在就可以理解输出结果了吧。
这里要强调一点,看到”=”并不等于调用了Operator=()的代码,以下三种情况其实是等效的,都只调用了拷贝构造函数:
Vector b(a);
Vector b = a;
Vector b = Vector(a);
最精彩的部分在于,如果你用
cl /Ox
编译代码,使优化达到最大,再次运行,得到如下结果:
-- Test add() --
Default Constructor was called.[0x0012ff74]
---- Constructors were called 1 times. ----
这次,只调用了默认构造函数。这样的修改被称作Named Return Value(NRV) Optimization。
什么是NRV优化呢,顾名思义,就是保存返回值的变量不再使用没名没姓的__temp0这样的东西了,而是直接把c作为返回变量,因此应该将NRV翻译为“有名字的返回变量”吧,侯捷翻译的《深入探索C++对象模型》居然把它称为“具名数值”,真是不知所云。
言归正传,NVR优化的伪代码如下:
Vector c;
add(c, a, b);
NVR优化的最大好处就是不会再去调用那次多余拷贝构造函数了(把__temp0拷贝到c),因此《深入探索C++对象模型》67页最下面才会说第一版没有拷贝构造函数,所以不能进行优化。其实是指优化的意义不大,或者说没有什么可优化的。
![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKYAAAC6CAIAAACr/qHAAAAgAElEQVR4nO2de1QTZ/7/OW0JKt6qPdvtbv1ae2Ttb3e9sV3b0nQdBIlarAW7Fdeuqw2nVWohbiO1SCuiIFbFqqAChnARb1gVRROQq9xygxByIZOQhHBJuIVbFAkE+P3x1NmYAIYwDAPyPu/jeZj5zJM4rzyXeeaTiZ2vry80QeTr6zswJZuk1+u7uroMBkNvb68dBEHj/X6s1QR6q3hTeXm5TCbTaDSdnZ0TDLlGo2lubh7vNzLxlJKSwmQy+Xy+VqudeMg1Gs14v5GJp6CgoOjoaCaTKZfLp5C/ENqyZUtQUND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Fdg+isFYS9lnFheLc0RSyrPRkX961/bSLbKy8tr0iD/6KOPvvrqqwsXLnA4HDuwSYgn8bmFD27Gxh/Zcuv4+tsRHx3bNmf/v9+9evkSl8uFYVipVLa2tra2tra1tbW1tSlVquP7P4/zf/MqdXry3vk3Tm1t1KgfPXrU0NCgQUnjSwsVubi4kMnkc+fOsdns35CLxeLxBm2tRCIRWiytUUNDw/jSQkWurq67d++OjY3lcrl2er1eLpdnZGQcO3Zs+/btrq6u77333gcffLB69Wp3d3ePKU1MkUikdevWbdiwYcOGDevWrfv888+DgoJSUlIEAoFdV1dXbW0ti8VKSkoKCQnx8/PbuXMnmUzetWvXnj17vp3SxJS/v39AQACFQtm7d29AQMCBAweio6OZTKZMJrPr7u5uaWmRyWR5eXnXrl2LjY2NioqKjo6OiYmJi4u7OKWJKRqNRqPR4uPj6XQ6jUZLSUlhMBh8Pl+j0dj19vY+fvy4paVFpVIJhUIul8tisVgsFofD4U1pIqvURAKBQCaTabVavV7//wFONyVClTzuGwAAAABJRU5ErkJggg==)
但是这样带来的坏处是,如果你在拷贝构造函数里面放上与拷贝无关的代码,比如我放入的printf和count++,那么这些东西就不会被调用了,产生优化前后代码不一致问题。所以大家要在此注意一下。
http://www.linuxso.com/linuxbiancheng/5726.html