Is incrementing a null pointer well-defined?

后端 未结 9 475
情话喂你
情话喂你 2020-12-03 04:17

There are lots of examples of undefined/unspecified behavior when doing pointer arithmetics - pointers have to point inside the same array (or one past the end), or inside t

9条回答
  •  青春惊慌失措
    2020-12-03 05:08

    §5.2.6/1:

    The value of the operand object is modified by adding 1 to it, unless the object is of type bool [..]

    And additive expressions involving pointers are defined in §5.7/5:

    If both the pointer operand and the result point to elements of the same array object, or one past the last element of the array object, the evaluation shall not produce an overflow; otherwise, the behavior is undefined.

提交回复
热议问题