Crash in C++ code due to undefined behaviour or compiler bug?

后端 未结 3 1978
夕颜
夕颜 2021-02-19 01:15

I am experiencing strange crashes. And I wonder whether it is a bug in my code, or the compiler. When I compile the following C++ code with Microsoft Visual Studio 2010 as an op

3条回答
  •  温柔的废话
    2021-02-19 01:20

    You take &v1 into c.p and later using operator ++ you advance it. You cannot rely on the ordering of the stack, therefore comes undefined behavior ((&v1)+1 != &v2)

提交回复
热议问题