3 ms·
I'm not sure that's undefined though. It's equivalent to ... void myfunc(struct foo *p) { int *t = (int *)((char *)p + offsetof(p->bar)); ...
by PeCaN 11y ago
I'm not sure that's undefined though. It's equivalent to
...
void myfunc(struct foo *p) {
int *t = (int *)((char *)p + offsetof(p->bar));
...
}
right? In the C abstract machine taking the address of an offset of a pointer is always defined, I think.
- deleted 11y ago[deleted]
- __s 11y agoIt is not always defined. It's defined to take an address to a pointer with an offset within the object's space plus one. Subtracting two pointers to distinct objects is undefined. This is to allow for segmented memory architectures. It's also to allow implementation of garbage collectors by the compiler