3 ms·
The first line is not actually dereferencing anything - it's taking the address of the pointer, and returning another pointer with offset p from the original on
by paskozdilar 5y ago
The first line is not actually dereferencing anything - it's taking the address of the pointer, and returning another pointer with offset p from the original one.
As far as I know, C allows arbitrary pointer arithmetic (including pointing to an out-of-bounds address) as long as you don't read/write into the invalid memory. If the p check fails, nothing will be done with pfd.
If I'm wrong, please correct me.
- rssoconnor 5y agohttps://news.ycombinator.com/item?id=30956370 https://news.ycombinator.com/item?id=30956370
- MrRadar 5y agoUnfortunately you are not correct. Pointer arithmetic is only valid if the resulting calculated address is within the bounds of the same array as the original pointer, or calculates an address that is just past the end of the array. Otherwise it is our old friend undefined behavior. See section 6.5.6 of the C11 spec.