<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 05/01/2017 02:31 PM, Daniel Berlin
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAF4BwTUGDOsZiFktGgap1KGVKsOFvkcc-o-DWv47=6Tms71maQ@mail.gmail.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <div dir="ltr">
        <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">
                <div class="gmail_extra">
                  <div class="gmail_quote"><span class="">
                      <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"><br>
                          <br>
                        </div>
                      </blockquote>
                      <div><br>
                      </div>
                    </span>
                    <div>So you believe that you can index into an
                      object randomly by pointer arithmetic and pull out
                      a different field?<br>
                      <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>
            <div>IE at best you'd have to add</div>
            <div><br>
            </div>
            <div> &(struct X*(0))->b - &(struct X*(0))->a</div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    I don't think that helps because the structure offsets are an
    observable part of the model. The code could easily be:<br>
    <br>
    if (offsetof(X, b) == sizeof(int)) {<br>
      // thing we're talking about<br>
    } else {<br>
      // something safer<br>
    }<br>
    <br>
    <blockquote
cite="mid:CAF4BwTUGDOsZiFktGgap1KGVKsOFvkcc-o-DWv47=6Tms71maQ@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div class="gmail_extra"><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>
    <br>
    I'm sure that's true :-)<br>
    <br>
     -Hal<br>
    <br>
    <pre class="moz-signature" cols="72">-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory</pre>
  </body>
</html>