<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 924: structs with internal padding</title>
<meta property="og:title" content="Issue 924: structs with internal padding">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue924.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#Resolved">Resolved</a> status.</em></p>
<h3 id="924"><a href="lwg-defects.html#924">924</a>. structs with internal padding</h3>
<p><b>Section:</b> 32.5 <a href="https://wg21.link/atomics">[atomics]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Herb Sutter <b>Opened:</b> 2008-10-17 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#atomics">issues</a> in [atomics].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p>
Right now, the <code>compare_exchange_weak</code> loop should rapidly converge on the
padding contents. But <code>compare_exchange_strong</code> will require a bit more
compiler work to ignore padding for comparison purposes.
</p>
<p>
Note that this isn't a problem for structs with no padding, and we do
already have one portable way to ensure that there is no padding that
covers the key use cases: Have elements be the same type. I suspect that
the greatest need is for a structure of two pointers, which has no
padding problem. I suspect the second need is a structure of a pointer
and some form of an integer. If that integer is <code>intptr_t</code>, there will be
no padding.
</p>
<p>
Related but separable issue: For unused bitfields, or other unused
fields for that matter, we should probably say it's the programmer's
responsibility to set them to zero or otherwise ensure they'll be
ignored by <code>memcmp</code>.
</p>

<p>
<b>Proposed resolution:</b> Using
<code>atomic&lt;struct-with-padding&gt;::compare_exchange_strong</code> should be either:
</p>

<ol>
<li>
ill-formed, or
</li>
<li>
well-defined.
</li>
</ol>

<p>
I propose Option 1 for C++0x for expediency, though I'm not sure how to
say it. I would be happy with Option 2, which I believe would mean that
<code>compare_exchange_strong</code> would be implemented to avoid comparing padding
bytes, or something equivalent such as always zeroing out padding when
loading/storing/comparing. (Either implementation might require compiler
support.)
</p>

<p><i>[
Summit:
]</i></p>


<blockquote><p>
Move to open. Blocked until concepts for atomics are addressed.
</p></blockquote>

<p><i>[
Post Summit Anthony adds:
]</i></p>


<blockquote><p>
The resolution of LWG <a href="lwg-defects.html#923" title="atomics with floating-point  (Status: Resolved)">923</a><sup><a href="https://cplusplus.github.io/LWG/issue923" title="Latest snapshot">(i)</a></sup> should resolve this issue as well.
</p></blockquote>

<p><i>[
2009-10 Santa Cruz:
]</i></p>


<blockquote><p>
<del>NAD Editorial</del><ins>Resolved</ins>.  Addressed by
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2992.htm">N2992</a>.
</p></blockquote>



<p id="res-924"><b>Proposed resolution:</b></p>
<p>
</p>





</body>
</html>
