2015年8月6日 星期四

Visual Studio C++ Return Value Optimization is the Best (RVO)


Intel Core i7-3770 @ 3.40Ghz
Windows 7 Professional 64-bit
Visual Studio 2010 Version 10.0.40219.1 SP1Rel


#include <iostream>

struct C {
  C() {}
  C(const C&) { std::cout << "A copy was made.\n"; }
};

C f() {
  return C();
}

int main() {
  std::cout << "Hello World!\n";
  C obj = f();
  system("PAUSE");
  return 0;
}


Depending upon the compiler, and that compiler's settings, the resulting program may display any of the following outputs:
Hello World!
A copy was made.
A copy was made.
Hello World!
A copy was made.
Hello World!


The console output is:
Hello World!

沒有留言:

張貼留言

2023 Promox on Morefine N6000 16GB 512GB

2023 Promox on Morefine N6000 16GB 512GB Software Etcher 100MB (not but can be rufus-4.3.exe 1.4MB) Proxmox VE 7.4 ISO Installer (1st ISO re...