Visual Studio not able to show the value of 'this' in release mode (with debug information)

后端 未结 8 645
感情败类
感情败类 2020-12-29 11:15

Original question:

Why is the this pointer 0 in a VS c++ release build?

When breaking in a Visual Studio 2008 SP1 release build with the /Zi

8条回答
  •  余生分开走
    2020-12-29 12:00

    Because it is a release build. The entire point in optimizations is to change the implementation details of the program, while preserving the overall functionality.

    Does the program still work? Then it doesn't matter that the this pointer is seemingly null.

    In general, when you're working with a release build, you should expect that the debugger is going to get confused. Code is going to be reordered, variables removed entirely, or containing weird unexpected values.

    When optimizations are enabled, no guarantees are given about any of these things. But the compiler won't break your program. If it worked without optimizations, it'll still work with optimizations. If it suddenly doesn't work, it's because you have a bug that was only exposed because the compiler optimized and modified the code.

提交回复
热议问题