2 ms·
Now this is a really interesting one. I’m assuming this trivially applies to index array access as well?
by catlifeonmars 2y ago
Now this is a really interesting one. I’m assuming this trivially applies to index array access as well?
- kevincox 2y agoI think this technically wouldn't be a null pointer anymore. As array indexing `p[n]` is defined as `*(p + n)` so first you create a new pointer by doing math on a null pointer (which is UB in C) then dereferencing this new pointer (which doesn't even really exist because you have already committed UB).
- tialaramex 2y agoIn C, and this article seems to be almost exclusively about C, a[b] is basically sugar for (*((a) + (b))) C does actually have arrays (don't let people tell you it doesn't) but they decay to pointers at ABI fringes and the index operation is, as we just saw, merely a pointer addition, it's not anything more sophisticated - so the arrays count for very little in practice.
- juped 2y agoNot just basically sugar, the classic parlor trick is doing 3[arr] or whatever
- catlifeonmars 2y agoParty trick? That’s just good coding style. I even have that enabled as a lint rule /s