C++/CLI quiz: What is the exact callstack?

I have a small quiz:
Here is a small code, compiled with “/clr” (this is important).
Can you tell me, what is the exact callstack inside the method “Foo”?
(And how can you prove this)

struct V
{
  V() {}
  V(const V &v) 
  {
    this->i = v.i;
  }
  int i;
};

class C
{
public:
  void CallFoo()
  {
    V v;
    Foo(v);
  }
  virtual void Foo(V v)
  {
    // TODO: What is the callstack!?
  }
};

int main()
{
  C c;
  c.CallFoo();
}

Any hints can be posted as comments.
By the way: VS208 does not show you the exact callstack, but it gives you a hint, that there is something that you do not see 😉

4 thoughts on “C++/CLI quiz: What is the exact callstack?

  1. tom

    Interesting,

    The /clr version creates one more V temp instance than that without the switch.

    Did you find out why?

  2. Ben Voigt [C++ MVP]

    The question is where the native->managed transition takes place. Or did you not want the entire call stack, all the way back to the native entry point which Windows places in the instruction pointer of the context of the first thread of your new process before making it runnable?

  3. Pingback: Jochen Kalmbach’s Blog » Blog Archive » C++/CLI quiz: Answer

Comments are closed.