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!

沒有留言:

張貼留言

2007 to 2023 HP and Dell Servers Comparison

  HP Gen5 to Gen11  using ChatGPT HP ProLiant Gen Active Years CPU Socket Popular HP CPUs Cores Base Clock Max RAM Capacity Comparable Dell ...