7 ms·
A pointer points to the start of its pointee - i.e. the point "just before" its pointee. That's how derived-to-base casts work. That's also how you can have "on
by arielby 11y ago
A pointer points to the start of its pointee - i.e. the point "just before" its pointee. That's how derived-to-base casts work. That's also how you can have "one-past-the-end" pointers, which are actually "just after" the relevant array.
for example, if you have the following structs
typedef struct { void *key; } base;
typedef struct { base b; int misc; int data[2]; } derived;
then derived is laid out as follows
-----+------+---------+---------+---------+-----
... | base | derived | data[0] | data[1] | ...
-----+------+---------+---------+---------+-----
^ ^ ^
| | |
base derived.data &derived.data[2]
- matchu 11y agoYep. A pointer is a memory range, but it supports a cast operation that allows you to change the pointer type, and therefore the end address. I think we agree, right? :)
- arielby 11y agoExcept you can have a void* that does not have an end address.
- matchu 11y agoHmm, yeah, void pointers are weird. I'd be inclined to say that its start and end address are the same and it's a range over 0 bytes of memory, and the fact that dereferencing fails is an artifact of the dereferencing operation itself... but I don't know enough about void pointer voodoo to know whether that's actually a consistent interpretation.