Does Visual C++ consider signed integer overflow undefined?

后端 未结 2 1166
梦毁少年i
梦毁少年i 2021-02-19 19:08

It\'s gotten a lot of attention lately that signed integer overflow is officially undefined in C and C++. However, a given implementation may choose to define it; in C++, an i

2条回答
  •  灰色年华
    2021-02-19 19:09

    Your example probably does have undefined behavior for n == INT_MAX, but not just because of signed integer overflow being undefined (which it may not be on the Microsoft compiler). Rather, you are probably invoking undefined out-of-bounds pointer arithmetic.

提交回复
热议问题