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

后端 未结 5 1927
说谎
说谎 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:05

    The compiler cannot see the implementation of delete[] and new[] and must assume it does.

    If you had implemented delete[] and new[] above it, the compiler may inline / optimize away those functions entirely.

提交回复
热议问题