Are there stackless or heapless implementation of C++?

后端 未结 7 1805
旧时难觅i
旧时难觅i 2020-11-29 09:32

C++ standard does not mention anything about the stack or the heap, they are implementation specific, which is true.

Even though they are not part o

7条回答
  •  伪装坚强ぢ
    2020-11-29 09:40

    This is essentially echo'ing Mr. TA's answer (+1 BTW). Stack and heap are abstract concepts.

    The new and delete operators (and malloc and free functions) are really just an interface to the abstraction called a heap. So, when you ask for a C++ implementation to be "heapless", you are really asking for the implementation to not allow you to use these interfaces. I don't think there is anything preventing an implementation from always failing these interfaces.

    Calling functions and resuming the current execution after the call returns (and optionally retrieving a return value) are interfaces to a stack abstraction. When you are asking for the C++ implementation to be "stackless", you are asking for the C++ implementation to disallow the program from performing these actions. I can't think of a conforming way for the compiler to impose this condition. The language dictates the source code be allowed to define functions, and to define code to call functions.

    So my answer in terms of what is possible: "stackless" no, "heapless" yes.

提交回复
热议问题