When does the function function of the parameter function turn off?

Suppose I have two functions, for example:

const char* getstr()
{
  std::string s = "somestring";
  return s.c_str();
}

second like:

void func(int x, const char* str)
{
    std::cout <<"x="<<x <<", str=" <<str<<std::endl;
}

Now suppose the func () function with something like

func(100,getstr());

My question is, when will the function stack for the getstr () function be disabled? After the body "func ()" is executed or before the body is executed?

I ask this because some genius in my team wrote this type of function "getstr ()". and somehow the system does not crash.

My understanding was that the stack for the getstr () function would be disabled as soon as this parameter was evaluated. But if this were so, then the code would have broken and this did not happen.

Can someone help me what the C ++ standard says?

+4
source share
1

s getstr. , getstr, .

+1

Source: https://habr.com/ru/post/1624204/


All Articles