<div dir="ltr">On Mon, May 1, 2017 at 6:40 PM, Daniel Berlin <span dir="ltr"><<a href="mailto:dberlin@dberlin.org" target="_blank">dberlin@dberlin.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">On Mon, May 1, 2017 at 3:09 PM, Daniel Berlin <span dir="ltr"><<a href="mailto:dberlin@dberlin.org" target="_blank">dberlin@dberlin.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><span class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">On Mon, May 1, 2017 at 2:07 PM, John McCall <span dir="ltr"><<a href="mailto:rjmccall@gmail.com" target="_blank">rjmccall@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div class="m_-4811635330834390567m_-7259718727137271957h5">On Mon, May 1, 2017 at 3:31 PM, Daniel Berlin <span dir="ltr"><<a href="mailto:dberlin@dberlin.org" target="_blank">dberlin@dberlin.org</a>></span> wrote:<br></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div class="m_-4811635330834390567m_-7259718727137271957h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div bgcolor="#FFFFFF">So you believe that you can index into an object randomly by pointer arithmetic and pull out a different field?<br></div></blockquote></span><div><br></div><div>For starters, this is  illegal because you don't know where the padding bytes are.</div><div>You cannot assume that X.a + 1 == X.b</div><div>"Implementation alignment requirements might
cause two adjacent members not to be allocated immediately after each other;"</div><div><br></div><div>See 9.2.14</div></div></div></div></blockquote><div><br></div></span><div>IE at best you'd have to add</div><div><br></div><div> &(struct X*(0))->b - &(struct X*(0))->a</div></div><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">I don't believe this is legal either.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Let me try to dredge up the long discussions we had about these cases on the gcc mailing lists.</div><div class="gmail_extra">The conclusion was, i believe:</div><div class="gmail_extra"><br></div><div class="gmail_extra">"if you want to go marching through an object as a char *, that's fine, if you expect to be able to get at fields by playing pointer arithmetic games, from other fields, that is not)</div><div class="gmail_extra">I feel like every couple years, a different compiler has the same aliasing discussions :)</div></div></blockquote><div><br></div></div></div><div>With the caveat that, in practice, compilers have to support both:</div><div>  a) "going up a level" by subtracting an offsetof, which is clearly officially intended and not otherwise supported,</div></div></div></div></blockquote><div><br></div></span><div>AFAIK, Vtable accesses were supported by doing this, but pretty much nothing else.</div></div></div></div></blockquote><div><br></div></span><div>and to be clear, i mean given:<br><br></div><div>struct a</div><div>{ </div><div>int a;</div><div> struct b bstruct;</div><div>}; </div><div><br></div><div>given a pointer to bstruct, subtracting sizeof(int)  is not going to give you a pointer to a struct a.</div></div></div></div></blockquote><div><br></div><div>If sizeof(int) happens to equal offsetof(struct a, bstruct), it sure should (if you're doing the pointer arithmetic on an appropriate type, of course).</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>It was allowed to work for vtable accesses.</div></div></div></div></blockquote><div><br></div><div>I would like to once again remind you that random mailing list conversations you happened to be in but can't even remember from some completely unnamed and possibly different context are neither authoritative nor binding on us now. :)</div><div><br></div><div>John.</div></div>
</div></div>