3 ms·
> First, it is a big mistake to try to understand pointers in a programming language as if they follow the same rules as pointer-sized integer values. I’m a bi
by dahart 8y ago
> First, it is a big mistake to try to understand pointers in a programming language as if they follow the same rules as pointer-sized integer values.
I’m a bit confused by this statement. I don’t know the C & C++ standards, but isn’t pointer arithmetic defined and allowed within the bounds of the heap allocation of the base pointer? Like, on an array for example, aren’t pointers required to “follow the same rules as pointer-sized integer values”, as long as you’re not indexing outside your array allocation?
Wouldn’t the issue here be more clearly stated as “don’t use pointer arithmetic to index outside the bounds of the base pointer’s allocation” rather than “never use pointer artithmetic”?
- camgunz 8y agoYeah it's fine inside an array, but as soon as you move a pointer from one allocation to another, boom. Dunno what it means for stack pointers though, probably the same except now you've made it so they can't be registers.