Is memcpy(&a + 1, &b + 1, 0) defined in C11?

后端 未结 2 1613
生来不讨喜
生来不讨喜 2020-12-17 08:00

This question follows this previous question about the definedness of memcpy(0, 0, 0), which has been conclusively determined to be undefined behavior.

2条回答
  •  失恋的感觉
    2020-12-17 08:45

    C11 says:

    (C11, 7.24.2.1p2) "The memcpy function copies n characters from the object pointed to by s2 into the object pointed to by s1."

    &a + 1 itself is a valid pointer to integer addition but &a + 1 is not a pointer to an object, so the call invokes undefined behavior.

提交回复
热议问题