2 ms·
> Is it actually? Yes, the extra data being the length that is located in memory before the pointer. > So suppose I pass this "fully compatible with normal po
by saagarjha 7y ago
> Is it actually?
Yes, the extra data being the length that is located in memory before the pointer.
> So suppose I pass this "fully compatible with normal pointers" pointer to a function.. and it ends up being stored in a register. Now where is this location "just before the pointer"? In the previous register?
You’re at the wrong level of indirection; the header in in the memory before what the pointer points to, as in p - 1 rather &p - 1.
> I think it is describing arrays with a prepended length header.
Correct.
> Call it a fat pointee if you want a fancy name; at least that acknowledges the onus is on the pointee to have the right metadata in the right place.
I would prefer that this was not called a “fat pointer”, but the claim made above is that a pointer with any implicit data associated with it is “fat”.
> There's nothing in the pointer here.
No data, but there is an implicit guarantee that it points to the data portion of a length-prepended array.
- clarry 7y ago> Yes, the extra data being the length that is located in memory before the pointer. > You’re at the wrong level of indirection; the header in in the memory before what the pointer points to, as in p - 1 rather &p - 1. You are contradicting yourself. &p - 1 is before the pointer. p - 1 is before the pointee. > I would prefer that this was not called a “fat pointer”, but the claim made above is that a pointer with any implicit data associated with it is “fat”. > No data, but there is an implicit guarantee that it points to the data portion of a length-prepended array. I think that's a borderline useless definition. In my C, there's an implicit guarantee that any pointer, in a context where it may be dereferenced, points to a valid object (as long as it's not NULL and there's no programming error causing it to point at nothing well defined). Usually it points at the start of a struct, sometimes it points at list node (or whatever) embedded in a struct and I might have to work my way back with offsetof. Either virtually all of my pointers are fat or none of them are. I go by that none of them are, because whatever data I have (implicit or explicit) is not a property of the pointers I use but of the data I point them to.