News for hackers. Stuff that matters.
Re:Essential C [pdf] by pjmlp on Sunday March 06, 2022 @02:50PM (#30580574)
Out of bounds is only defined for length + 1, for anything else anything goes.
Re:Essential C [pdf] by MaxBarraclough on Sunday March 06, 2022 @04:56PM (#30581680)
That doesn't sound right. C (and C++) permit you to do pointer arithmetic to derive a pointer value pointing to one element beyond the final element of an array. This special treatment doesn't extend to dereferencing though - if you deference that pointer, that's UB.

If you do pointer arithmetic to derive a pointer value pointing 2 or more elements beyond the final element of an array, that's undefined behaviour, even if you never dereference that pointer.

Re:Essential C [pdf] by pjmlp on Sunday March 06, 2022 @05:29PM (#30581920)
Sure, I just didn't want to spend too much time explaining all details, my failure.