<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 17, 2015 at 11:15 PM, Daniel Berlin <span dir="ltr"><<a href="mailto:dberlin@dberlin.org" target="_blank">dberlin@dberlin.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra">[..]<div><div style="font-family:arial,helvetica,sans-serif;font-size:10pt;color:rgb(0,0,0)">I don't understand what this means. How should they do that? </div></div><div class="gmail_quote"><div><div class="h5"><div><br></div></div></div><div>So, his point was the arrays have no connections to the union. This is not the only case this occurs in.</div><div><br></div><div>Let's take the canonical example:</div><div><br></div><div><br></div><div>For example</div><div><br></div><div>union foo {</div><div>int a;</div><div>float b;</div><div>};</div><div><br></div><div>int ihateunions(int *a, float *b)</div><div>{</div><div><do a thing with a and b></div><div>}</div><div><br></div><div>int passtounion()</div><div>{</div><div>union foo bar;</div><div>ihateunions(&bar.a, &bar.b);</div><div><br></div><div>}</div><div><br></div><div>Inside ihateunions, you will have no idea that a and b are connected to unions.</div><div><br></div><div>Let's say this example is easy, i mean, they are both at offset 0, so they can alias, right?</div><div><br></div></div></div></div></blockquote><div><br></div><div>My understanding is that if you access members of a union in this way,  the compiler is allowed<br></div><div>to assume that a and b do not alias.<br><br></div><div>If you access a member (or nested member) of a union, starting from the union itself, then it depends if the other type is also accessible through the union.<br><br><br></div><div>So:<br><br></div><div>int foo(union foo* a, float* b, int* c) {<br></div><div>  a->a=1;<br></div><div>  *b=2;<br></div><div>  // compiler must assume a->a and *b can alias<br></div><div>  // compiler must not assume *b and *c alias (access not through union)<br></div><div>}<br><br></div><div>(Also see section 3.10 of the c++03 standard; and <a href="http://stackoverflow.com/questions/98650/what-is-the-strict-aliasing-rule">http://stackoverflow.com/questions/98650/what-is-the-strict-aliasing-rule</a> )<br><br><br></div>Greetings,<br clear="all"></div> <br><div class="gmail_signature">Jeroen Dobbelaere<br></div>
</div></div>