{"id":868,"date":"2022-08-30T15:08:31","date_gmt":"2022-08-30T15:08:31","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/two-arrays-in-a-union-in-c-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:08:31","modified_gmt":"2022-08-30T15:08:31","slug":"two-arrays-in-a-union-in-c-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/two-arrays-in-a-union-in-c-collection-of-common-programming-errors\/","title":{"rendered":"Two arrays in a union in C++-Collection of common programming errors"},"content":{"rendered":"<p>Both arrays are required to have the same size and layout. Of course, if you initialize anything using <code>m_V<\/code>, then all accesses to <code>m_M<\/code> are undefined behavior; a compiler might, for example, note that nothing in <code>m_V<\/code> has changed, and return an earlier value, even though you&#8217;ve modifed the element through <code>m_M<\/code>. I&#8217;ve actually used a compiler which did so, in the distant past. I <em>would<\/em> avoid accesses where the union isn&#8217;t visible, say by passing a reference to <code>m_V<\/code> and a reference to <code>m_M<\/code> to the same function.<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-09 22:49:58. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Both arrays are required to have the same size and layout. Of course, if you initialize anything using m_V, then all accesses to m_M are undefined behavior; a compiler might, for example, note that nothing in m_V has changed, and return an earlier value, even though you&#8217;ve modifed the element through m_M. I&#8217;ve actually used [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-868","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/868","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=868"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/868\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=868"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=868"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=868"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}