Commit 4264d78d authored by Jens Gustedt's avatar Jens Gustedt
Browse files

a more explicit version of n1951 as requested by Blaine

parent 483da03c
......@@ -33,8 +33,8 @@ code { background-color : #EEE; text-style : sans-serif }
2015-08-07 <br/>
<b>Reference Document: </b>n1951<br/>
<b>Version:</b> 1.0<br/>
<b>Date:</b> 2015-08-07<br/>
<b>Version:</b> 2.0<br/>
<b>Date:</b> 2016-04-11<br/>
<b>Subject:</b> Problem with the specification of ATOMIC_VAR_INIT</p>
......@@ -59,7 +59,35 @@ initialization-compatible with value.
or <code>union</code> types properly.
<p><b>Problem discussion</b></p>
Consider the following <code>struct</code> type that represents the
head of a linked list.
<code>struct head { size_t n; struct elem* first; };</code><br/>
A non-trivial initialization <em>in file scope</em> of an object of
that type could attempt to initialize both fields of the structure
with non-zero values <code>1</code> for <code>n</code>
and <code>toto</code> for <code>first</code>. Of the three
<code>_Atomic(struct head) top = ATOMIC_VAR_INIT(.n = 1, .first = toto);</code><br/>
<code>_Atomic(struct head) top = ATOMIC_VAR_INIT({.n = 1, .first = toto});</code><br/>
<code>_Atomic(struct head) top = ATOMIC_VAR_INIT(((struct head){.n = 1, .first = toto}));</code><br/>
none is valid as the standard document stands. The first two are not
values of any type, and the third uses a compound literal that is
not a constant expression as a file scope initialization would require.
<p><b>Problem discussion</b></p>
As a consequence, there is a problem for atomic objects that combine
......@@ -106,7 +134,7 @@ initialization-compatible with value.
<p><b>Current practice</b></p>
<p><b>Current practice</b></p>
Both compilers that I have my hands on (gcc 4.9 and clang 3.6) that
......@@ -138,7 +166,22 @@ syntax if <code>VALUE</code> is a <code>{ }</code> initializer.
<p><b>Suggested Technical Corrigendum</b><br/></p>
<p>Change the beginning of the corresponding section,, to:</p>
<p>Change the beginning of the corresponding section,, from:</p>
<p class="quote"> The <code>ATOMIC_VAR_INIT</code> macro<br/>
<code>#include &lt;stdatomic.h&gt;</code><br/>
<code>#define ATOMIC_VAR_INIT(C value)</code></br>
The <code>ATOMIC_VAR_INIT</code> macro expands to a token sequence suitable for initializing an
atomic object of a type that is initialization-compatible with value.
An atomic object with automatic storage duration ...
<p class="alternative"> The <code>ATOMIC_VAR_INIT</code> macro<br/>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment