2

I just watched Jason Turners C++ Code Smells talk from the last CppCon'19 and paused at 7.37m, where he talks about output parameters.

https://youtu.be/f_tLQl0wLUM?t=457

The function in question (see GodBolt link), has a return value. His question is, how many parameters does this function take and the answer is 1. I am trying to understand what that means.

std::string get_value();

int main()
{
    const auto value = get_value();
}

The resulting (and interesting part of that) assembly is this:

...
mov     rdi, rsp
...

He said rdi is the register for the first parameter, but I don't know what the point of this code piece is. Does that mean the compiler created a hidden [out] parameter instead of the return value? Could someone elaborate what that means?

Peter Cordes
  • 286,368
  • 41
  • 520
  • 731
Daniel Stephens
  • 1,649
  • 6
  • 23
  • 59

0 Answers0