<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">

<title>C++ Freestanding and Conditionally Supported</title>

<style type="text/css">
table { border: 1px solid black; border-spacing: 0px }
caption { font-weight: bold }
th { text-align: left; vertical-align: top;
     padding: 0.5em; border: 1px solid black }
td { text-align: left; vertical-align: top;
     padding: 0.5em; border: 1px solid black }
dt { font-weight: bold; }
ins { background-color: #A0FFA0; }
del { background-color: #FFA0A0; }
</style>
</head>

<body>

<h1>C++ Freestanding and Conditionally Supported</h1>

<p>
ISO/IEC JTC1 SC22 WG21 N3280 = 11-0050 - 2011-03-24
</p>

<p>
Lawrence Crowl, crowl@google.com, Lawrence@Crowl.org
<br>
Alberto Ganesh Barbati, ganesh@barbati.net
</p>

<p>
This paper is a revision of N3256 = 11-0026 - 2011-02-27.
</p>

<p>
<a href="#Introduction">Introduction</a><br>
<a href="#Wording">Wording Changes</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#Predefined.cpp.predefined">16.8 Predefined macro names [cpp.predefined]</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#compliance">17.6.1.3 Freestanding implementations [compliance]</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#CondContents.thread.threads">30.3 Threads [thread.threads]</a><br>
</p>


<h2><a name="Introduction">Introduction</a></h2>

<p>
CD comment DE 18 requested a macro to indicate the presence of threads.
The response was a rather convoluted "ineffective &lt;thread&gt; header".
This response failed to solve the real problem,
and caused FCD comment GB 55.
In addition,
the change exacerbated incompatibilities between C and C++.
</p>

<p>
This paper provides the minimal fixes in this area for C++0x.
They specifically satisfy
</p>

<dl>
<dt>CD DE 18 Compile-time detection of advanced features</dt>
<dd>
<p>
A macro that indicates the presence of threads in the core language
is generally more applicable
than one that only indicates the availability of library components.
This approach is consistent with the wording in 1.10 [intro.multithread].
</p>
</dd>

<dt>FCD GB 55 Freestanding &lt;ratio&gt; and &lt;chrono&gt;</dt>
<dd>
<p>
The &lt;mutex&gt; header
is more likely to be implemented in freestanding implementations
than is &lt;thread&gt;
and yet their freestanding requirements are opposite.
Furthermore, there are many single-threaded embedded systems.
So, &lt;thread&gt; should not be required of freestanding implementations.
Consequently,
&lt;ratio&gt; and &lt;chrono&gt; would not need to be freestanding
and GB 55 would become moot.
</p>
</dd>

<dt>C1X Freestanding Compatiblity</dt>
<dd>
<p>
The set of freestanding headers required by C++
should include at least those required by C.
Implementors will anyway because few would support only C++,
so failing to support those headers simply invites
an inconsistency between the standard and practice.
</p>
</dd>

</dl>

<h2><a name="Wording">Wording Changes</a></h2>

<h3><a name="Predefined.cpp.predefined">16.8 Predefined macro names [cpp.predefined]</a></h3>

<p>
Add the following to the end of paragraph 2.
</p>

<blockquote>
<dl>
<dt><ins><code>__STDCPP_THREADS__</code></ins></dt>
<dd>
<ins>Defined, and has the integer value constant 1,
if and only if
a program can have more than one thread of execution
(1.10 intro.multithread).</ins>
</dd>
</dl>
</blockquote>

<h3><a name="compliance">17.6.1.3 Freestanding implementations [compliance]</a></h3>

<p>
Edit table 16 as follows.
</p>

<blockquote>
<table>
<caption>Table 16 &mdash; C++ headers for freestanding implementations</caption>
<thead>
<tr><th></th><th>Subclause</th><th>Header(s)</th></tr>
</thead>
<tbody>
<tr><td><ins>17.6.1.2, C.2.2.3</ins></td><td><ins>Named operators</ins></td>
<td><ins><code>&lt;ciso646&gt;</code></ins></td></tr>
<tr><td>18.2</td><td>Types</td>
<td><code>&lt;cstddef&gt;</code></td></tr>
<tr><td>18.3</td><td>Implementation properties</td>
<td><code><ins>&lt;cfloat&gt;</ins>
&lt;limits&gt; <ins>&lt;climits&gt;</ins></code></td></tr>
<tr><td><ins>18.4</ins></td><td><ins>Integer types</ins></td>
<td><ins><code>&lt;cstdint&gt;</code></ins></td></tr>
<tr><td>...</td><td>...</td><td>...</td></tr>
<tr><td>18.10</td><td>Other runtime support</td>
<td><code><ins>&lt;cstdalign&gt;</ins>
&lt;cstdarg&gt;
<ins>&lt;cstdbool&gt;</ins>
</code></td></tr>
<tr><td>...</td><td>...</td><td>...</td></tr>
<tr><td>29</td><td>Atomics</td>
<td><code>&lt;atomic&gt;</code></td></tr>
<tr><td><del>30.3</del></td><td><del>Threads</del></td>
<td><del><code>&lt;thread&gt;</code></del></td></tr>
</tbody>
</table>
</blockquote>

<p>
Edit paragraph 3 as follows.
</p>

<blockquote>
<p>
The supplied version of the header <code>&lt;cstdlib&gt;</code>
shall declare at least the functions
<code>abort</code>, <code>atexit</code>, <code>at_quick_exit</code>,
<code>exit</code>, and <code>quick_exit</code> (18.5).
<del>The supplied version of the header <code>&lt;thread&gt;</code>
shall meet the same requirements as for a hosted implementation
or including it shall have no effect.</del>
The other headers listed in this table
shall meet the same requirements as for a hosted implementation.
</p>
</blockquote>

<h3><a name="CondContents.thread.threads">30.3 Threads [thread.threads]</a></h3>

<p>
Edit the synopsis as follows.
</p>

<blockquote>
<pre><code>
namespace std {
  <del>#define __STDCPP_THREADS__ __cplusplus</del>
</code></pre>
<p>
....
</p>
</blockquote>

</body>
</html>
