C++ call stack not in standard?

2019-07-12 08:27发布

问题:

Does the C++ standard talk about the call stack? It's common knowledge how stack and heap are used in C++, but I was reading through the standard and found no mention of it.

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1905.pdf

Is this something that's left up to the compiler implementation, but everyone agrees on, or did I miss something while browsing the doc?

回答1:

It isn't mentioned in the standard. Neither the stack nor the heap are. The standard describes the syntax and the semantics(the behavior) of C++ programs. The implementations choose to implement it as they wish.

However when you see how calls to functions must behave, there isn't a really wide choice. There has to be some sort of a stack to store local variables!



回答2:

The standard talks about storage duration instead of stack and heap. How those are implemented is up to ... implementation.