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.
[ Parent
| on HN ]
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.