|
|
|
|
|
by arielby
3948 days 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]
|
|