Does allocating memory and then releasing constitute a side effect in a C++ program?

后端 未结 5 1930
说谎
说谎 2020-12-19 00:52

Inspired by this question about whether the compiler can optimize away a call to a function without side effects. Suppose I have the following code:

delete[]         


        
5条回答
  •  温柔的废话
    2020-12-19 01:03

    new[] and delete[] could ultimately result in system calls. Additionally, new[] might throw. With this in mind, I don't see how the new-delete sequence can be legitimately considered free from side effects and optimized away.

    (Here, I assume no overloading of new[] and delete[] is involved.)

提交回复
热议问题