4 ms·
> It relies on struct layout, and if anything has wider alignment than ptrdiff_t, it's broken. I think you're wrong about this. I'm pretty certain a pointer to
by wyufro 9y ago
> It relies on struct layout, and if anything has wider alignment than ptrdiff_t, it's broken.
I think you're wrong about this. I'm pretty certain a pointer to a struct is always equivilent to a pointer to the first member, except for the type. I went and looked it up in C11 (6.7.2.1 point 15):
> A pointer to a structure object, suitably converted, points to its initial member (or if that member is a bit-field, then to the unit in which it resides), and vice versa. There may be unnamed padding within a structure object, but not at its beginning.
Edit: A duh, the + sizeof(ptrdiff_t) is the part that's wrong. Yeah, agreed.
- rkangel 9y agoYes - this is what allows you to some semblance of struct inheritance. You can embed a structure as the first member in the 'derived' structure and then up and down cast as appropriate.