﻿<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8" />
  <title>C++17 should refer to C11 instead of C99</title>
</head>
<body>
  <table border="1">
    <tr>
      <th>Doc. No.:</th>
      <td>P0063R1</td>
    </tr>
    <tr>
      <th>Date:</th>
      <td>2016-02-12</td>
    </tr>
    <tr>
      <th>Reply to:</th>
      <td>Clark Nelson</td>
      <td>Hans-J. Boehm</td>
    </tr>
    <tr>
      <th>Email:</th>
      <td>clark.nelson@intel.com</td>
      <td>hboehm@google.com</td>
    </tr>
    <tr>
      <th>Audience:</th>
      <td>Library Evolution</td>
    </tr>
  </table>
  <h1>C++17 should refer to C11 instead of C99</h1>
  <h1>Introduction</h1>
  <p>This document is a follow-on to
    <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0063r0.html">P0063R0</a>,
    from the pre-Kona mailing.
    It goes into the details of the &ldquo;easy part&rdquo;
    described therein.
    Much of its rationale is not repeated here.</p>
  <h2>Signal handler restrictions</h2>
  <p>18.10p10 effectively says that a signal handler
    must be written in the common subset of C and C++.
    But C++ and C11 both have thread-local storage.
    Referencing C11 instead of C99 might be taken to suggest
    that it would be OK for a signal handler to reference
    a thread-local object.</p>
  <p>It turns out that there is a technicality/loophole
    by which this can be dodged.
    Because the associated keyword is spelled differently
    in C and C++, technically thread-local storage
    is not actually in the common subset of the two languages &ndash;
    even though both languages support the feature.</p>
  <p>While this state would not provide
    a satisfying long-term resolution,
    it is considered adequate to separate
    the deep technical issues of signal handlers
    from the broader, more editorial issues
    of updating the normative reference.
    Hans is writing P0270 to address signal handlers.</p>
  <p>This document also doesn't go into interoperability
    of threads or atomics
    in a mixed C/C++ program.</p>
  <h2>Header coverage</h2>
  <p>C11 made the <code>&lt;complex.h&gt;</code> header optional.
    Currently in C++, the <code>&lt;ccomplex&gt;</code> header
    maps directly to the <code>&lt;complex&gt;</code> header.
    Simply deleting the requirement
    for a <code>&lt;ccomplex&gt;</code> header
    is simpler, and may be better, than making it optional.
    Of course an implementation would not need to change
    in order to conform to the new state of affairs,
    but programs that use <code>&lt;ccomplex&gt;</code>
    instead of <code>&lt;complex&gt;</code>
    would cease to be strictly conforming.</p>
  <p>C11 also added five new headers:</p>
  <dl>
    <dt><code>&lt;stdatomic.h&gt;</code></dt>
    <dt><code>&lt;threads.h&gt;</code></dt>
    <dd>These are also optional in C11,
      and since their functionality is already provided in C++ by other means,
      it's not clear that inventing optional wrappers for them
      would be worth the effort.</dd>
    <dt><code>&lt;stdalign.h&gt;</code></dt>
    <dt><code>&lt;uchar.h&gt;</code></dt>
    <dd>C++ already covers these two,
      having inherited one of them from the C Unicode TR
      (later incorporated into C11),
      and having effectively jumped the gun on the other one.</dd>
    <dt><code>&lt;stdnoreturn.h&gt;</code></dt>
    <dd>All this provides is a single prettifying macro:
      <pre>#define noreturn _Noreturn</pre>
      In C++, <code>[[noreturn]]</code>
      is probably already considered pretty enough.</dd>
  </dl>
  <p>So it's not clear that C++ needs to add anything
    for any of these new headers.</p>
  <h2>Annex K &emsp; Bounds checking interfaces</h2>
  <p>C11 optionally added several dozen new functions
    to the standard library,
    as safer alternatives to existing standard C library functions.
    For example, <code>strcat_s</code> was added as an alternative to
    <code>strcat</code>.</p>
  <p>The declarations of these functions
    were added to the existing headers;
    backward compatibility was provided
    by requiring that they be controlled by the setting of a macro:
    <code>__STDC_WANT_LIB_EXT1__</code>.
    A program can suppress them by defining the macro to zero,
    or request them by defining the macro to one.
    Whether they are declared if the macro is not defined
    by the program is implementation-defined.</p>
  <p>At the most recent WG14 meeting,
    a proposal was considered
    (<a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1967.htm">N1967</a>)
    that these functions should be removed
    from a future revision of the standard.</p>
  <p>The wording changes in this paper don't address them.</p>
  <h2>Reference mechanism</h2>
  <p>Consider 17.5.1.5 paragraph 1:</p>
  <blockquote>
    <p>Paragraphs labeled &ldquo;See also:&rdquo;
      contain cross-references to the relevant portions
      of this International Standard
      and the ISO C standard,
      which is incorporated into this International Standard
      by reference.</p>
  </blockquote>
  <p>Elsewhere it says &ldquo;as if by inclusion&rdquo;;
    why does it here say &ldquo;by reference&rdquo;?</p>
  <h2>Annex C &emsp; Compatibility</h2>
  <p>The wording changes in this paper
    don't yet address Annex C.5.</p>
  <h2>Working draft changes</h2>
  <h3>1.2 &emsp; Normative references</h3>
  <p>Change paragraph 1:</p>
  <blockquote>
    <p>...</p>
    <ul>
      <li>...</li>
      <li>ISO/IEC 9899:<del>1999</del><ins>2011</ins>,
	<em>Programming languages &mdash; C</em></li>
      <li>ISO/IEC 9899:<del>1999</del><ins>2011</ins>/Cor
	1:<del>2001</del><ins>2012</ins>(E),
	<em>Programming languages &mdash; C,
	  Technical Corrigendum 1</em></li>
      <li><del>ISO/IEC 9899:1999/Cor.2:2004(E),
	<em>Programming languages &mdash; C,
	  Technical Corrigendum 2</em></del></li>
      <li><del>ISO/IEC 9899:1999/Cor.3:2007(E),
	<em>Programming languages &mdash; C,
	  Technical Corrigendum 3</em></del></li>
      <li>...</li>
      <li><del>ISO/IEC TR 19769:2004,
	<em>Information technology &mdash; Programming languages,
	their environments and system software interfaces &mdash;
	Extensions for the programming language C
	to support new character data types</em></del></li>
    </ul>
  </blockquote>
  <p>Change paragraph 2:</p>
  <blockquote>
    <p>The library described in Clause 7
      of ISO/IEC 9899:<del>1999</del><ins>2011</ins>
      <del>and Clause 7 of ISO/IEC 9899:1999/Cor.1:2001
	and Clause 7 of ISO/IEC 9899:1999/Cor.2:2003</del>
      is hereinafter called
	the <dfn>C standard library</dfn>.<sup>1</sup></p>
  </blockquote>
  <p>Delete paragraph 3:</p>
  <blockquote>
    <p><del>The library described in ISO/IEC TR 19769:2004
      is hereinafter called the <dfn>C Unicode TR</dfn>.</del></p>
  </blockquote>
  <h3>17.6.1.2 &emsp; Headers</h3>
  <p>Change paragraph 3:</p>
  <blockquote>
    <p>The facilities of the C standard Library
      are provided in <del>26</del> <ins>25</ins> additional headers,
      as shown in Table 15.</p>
  </blockquote>
  <p>Change table 15:</p>
  <blockquote>
    <pre>&lt;cassert>  &lt;cinttypes> &lt;csignal>   &lt;cstdio>  &lt;cwchar>
<del>&lt;ccomplex></del> &lt;ciso646>   &lt;cstdalign> &lt;cstdlib> &lt;cwctype>
&lt;cctype>   &lt;climits>   &lt;cstdarg>   &lt;cstring>
&lt;cerrno>   &lt;clocale>   &lt;cstdbool>  &lt;ctgmath>
&lt;cfenv>    &lt;cmath>     &lt;cstddef>   &lt;ctime>
&lt;cfloat>   &lt;csetjmp>   &lt;cstdint>   &lt;cuchar></pre>
  </blockquote>
  <p>Change paragraph 4:</p>
  <blockquote>
    <p>Except as noted in Clauses 18 through 30 and Annex D,
      the contents of each header <code>c</code><var>name</var>
      shall be the same as that of the corresponding header
      <var>name</var><code>.h</code>,
      as specified in the C standard library (1.2)
      <del>or the C Unicode TR, as appropriate,</del>
      as if by inclusion.
      In the C++ standard library, however,
      the declarations
      (except for names which are defined as macros in C)
      are within namespace scope (3.3.6)
      of the namespace <code>std</code>.
      It is unspecified whether these names
      (including any overloads added
      in Clauses 18 through 30 and Annex D)
      are first declared within the global namespace scope
      and are then injected into namespace <code>std</code>
      by explicit <var>using-declarations</var> (7.3.3).</p>
  </blockquote>
  <h3>18.2 &emsp; Types</h3>
  <p>Change reference to C standard for paragraph 9:</p>
  <blockquote>
    <p>See also: ... ISO C <del>7.1.6</del> <ins>7.19</ins>.</p>
  </blockquote>
  <h3>18.3.3 &emsp; C library</h3>
  <p>Change table 32:</p>
  <blockquote>
    <pre>DBL_DIG         DBL_MIN_EXP     FLT_MAX_EXP    LDBL_MANT_DIG
DBL_EPSILON     DECIMAL_DIG     FLT_MIN        LDBL_MAX_10_EXP
DBL_MANT_DIG    FLT_DIG         FLT_MIN_10_EXP LDBL_MAX_EXP
DBL_MAX         FLT_EPSILON     FLT_MIN_EXP    LDBL_MAX
DBL_MAX_10_EXP  FLT_EVAL_METHOD FLT_RADIX      LDBL_MIN
DBL_MAX_EXP     FLT_MANT_DIG    FLT_ROUNDS     LDBL_MIN_10_EXP
DBL_MIN FLT_MAX LDBL_DIG        LDBL_MIN_EXP
DBL_MIN_10_EXP  FLT_MAX_10_EXP  LDBL_EPSILON
<ins>DBL_HAS_SUBNORM FLT_HAS_SUBNORM LDBL_HAS_SUBNORM
DBL_DECIMAL_DIG FLT_DECIMAL_DIG LDBL_DECIMAL_DIG
DBL_TRUE_MIN    FLT_TRUE_MIN    LDBL_TRUE_MIN</ins></pre>
  </blockquote>
  <p>It looks like all the functionality represented by these macros
    is already available from <code>numeric_limits</code>.</p>
  <p>Change references to C standard:</p>
  <blockquote>
    <p>See also: ISO C <del>7.1.5,</del> 5.2.4.2.2, 5.2.4.2.1.</p>
  </blockquote>
  <h3>18.5 &emsp; Start and termination</h3>
  <p>Change paragraph 12:</p>
  <blockquote>
    <p>... [ <em>Note:</em>
      The standard file buffers are not flushed.
      See: ISO C <del>7.20.4.4</del> <ins>7.22.4.5</ins>.
      &mdash;<em>end note</em> ]</p>
  </blockquote>
  <p>Change reference to C standard for paragraph 4:</p>
  <blockquote>
    <p>See also: ... ISO C <del>7.10.4</del> <ins>7.22.4</ins>.</p>
  </blockquote>
  <h3>18.6.1.4 &emsp; Data races</h3>
  <p>Change paragraph 1:</p>
  <blockquote>
    <p>For purposes of determining the existence of data races,
      the library versions of <code>operator new</code>,
      user replacement versions of global <code>operator new</code>,
      the C standard library functions
      <ins><code>aligned_alloc</code>,</ins>
      <code>calloc</code> and <code>malloc</code>,
      the library versions of <code>operator delete</code>,
      user replacement versions of <code>operator delete</code>,
      the C standard library function <code>free</code>,
      and the C standard library function <code>realloc</code>
      shall not introduce a data race (17.6.5.9).
      Calls to these functions
      that allocate or deallocate a particular unit of storage
      shall occur in a single total order,
      and each such deallocation call shall happen before (1.10)
      the next allocation (if any) in this order.</p>
  </blockquote>
  <p>18.6.1.1 also references <code>malloc</code>,
    and reference to <code>aligned_alloc</code>
    should be made as well;
    that issue is addressed in <a>P0035</a>
    (Dynamic memory allocation for over-aligned data).
  </p>
  <h3>18.10 &emsp; Other runtime support</h3>
  <p>Change reference to C standard for paragraph 3:</p>
  <blockquote>
    <p>See also: ISO C <del>4.8.1.1</del>
      <ins>7.16.1.1</ins>.</p>
  </blockquote>
  <p>Change references to C standard for paragraph 4:</p>
  <blockquote>
    <p>See also: ISO C <del>7.10.4, 7.8, 7.6,</del> <ins>7.13</ins> <del>7.12</del>.</p>
  </blockquote>
  <p>7.10.4 referred to the <code>exit</code> family of functions;
    7.8 to <code>&lt;stdarg.h&gt;</code>;
    and 7.12 (possibly) to <code>&lt;time.h&gt;</code>.
    These other references may be relevant elsewhere,
    but not to this paragraph,
    which is solely about <code>setjmp</code>
    and <code>longjmp</code>.</p>
  <h3>19.3 &emsp; Assertions</h3>
  <p>Change paragraph 3:</p>
  <blockquote>
    <p>The contents are the same as the Standard C library header
      <code>&lt;assert.h></code><ins>,
      except that a macro named <code>static_assert</code>
	is not defined in header
	<code>&lt;cassert&gt;</code>
	or in header <code>&lt;assert.h&gt;</code></ins>.</p>
  </blockquote>
  <p>Note: This kind of problem is handled
    in a slightly different way
    in 18.10p7-8.</p>
  <h3>20.7.13 &emsp; C library</h3>
  <p>Change table 45:</p>
  <blockquote>
    <pre>Functions: calloc malloc  <ins>aligned_alloc</ins>
           free   realloc</pre>
  </blockquote>
  <p>Change paragraph 3:</p>
  <blockquote>
    <p>The functions <ins><code>aligned_alloc()</code>,</ins>
      <code>calloc()</code>,
      <code>malloc()</code>, and <code>realloc()</code>
      do not attempt to allocate storage
    by calling <code>::operator new()</code> (18.6).</p>
  </blockquote>
  <p>Change the reference to the C standard for paragraph 4:</p>
  <blockquote>
    <p>See also: ISO C Clause <del>7.11.2</del> <ins>7.22.3</ins>.</p>
  </blockquote>
  <p>Change paragraph 5:</p>
  <blockquote>
    <p>Storage allocated directly
      with <ins><code>aligned_alloc()</code>,</ins>
      <code>malloc()</code>, <code>calloc()</code>,
      or <code>realloc()</code>
      is implicitly declared reachable (see 3.7.4.3) on allocation,
      ....</p>
  </blockquote>
  <p>Change the reference to the C standard for paragraph 7:</p>
  <blockquote>
    <p>See also: ISO C Clause <del>7.11.2</del> <ins>7.24</ins>.</p>
  </blockquote>
  <h3>20.12.8 &emsp; Date and time functions</h3>
  <p>Change table 60:</p>
  <blockquote>
    <pre>Macros: NULL   CLOCKS_PER_SEC <ins>TIME_UTC</ins>
Types:  size_t clock_t        time_t
Struct: tm     <ins>timespec</ins>
Functions:
asctime clock  difftime       localtime strftime
ctime   gmtime mktime         time      <ins>timespec_get</ins></pre>
  </blockquote>
  <p>Change the references to the C standard for paragraph 2:</p>
  <blockquote>
    <p>See also: ISO C Clause <del>7.12</del> <ins>7.27</ins> <del>,
      Amendment 1 Clause 4.6.4.</del></p>
  </blockquote>
  <h3>21.8 &emsp; Null-terminated sequence utilities</h3>
  <p>Change the references to the C standard for paragraph 15:</p>
  <blockquote>
    <p>See also: ISO C <del>7.3, 7.10.7, 7.10.8, and 7.11.
      Amendment 1 4.4, 4.5, and 4.6</del>
      <ins>7.4, 7.22.7, 7.22.8, 7.24, 7.28, 7.29 and 7.30</ins>.</p>
  </blockquote>
  <h3>22.6 &emsp; C library locales</h3>
  <p>Change the reference to the C standard for paragraph 3:</p>
  <blockquote>
    <p>See also: ISO C Clause <del>7.4</del> <ins>7.11</ins>.</p>
  </blockquote>
  <h3>25.5 &emsp; C library algorithms</h3>
  <p>Change the reference to the C standard for paragraph 4:</p>
  <blockquote>
    <p>See also: ISO C Clause <del>7.10.5</del> <ins>7.22.5</ins>.</p>
  </blockquote>
  <h3>26.3 &emsp; The floating-point environment</h3>
  <p>For editorial consistency,
    replace everything from section header 26.3.1
    through paragraph 2 with the following:</p>
  <blockquote>
    <p><ins>Table <var>N</var> describes
      header <code>&lt;cfenv&gt;</code>.</ins></p>
    <ins>
      <table>
	<caption>Table <var>N</var> &mdash;
	Header <code>&lt;cfenv&gt;</code> synopsis</caption>
	<tr>
	  <td>Macros:</td>
	</tr>
	<tr>
	  <td><code>FE_DIVBYZERO</code></td>
	  <td><code>FE_OVERFLOW</code></td>
	  <td><code>FE_DOWNWARD</code></td>
	  <td><code>FE_UPWARD</code></td>
	</tr>
	<tr>
	  <td><code>FE_INEXACT</code></td>
	  <td><code>FE_UNDERFLOW</code></td>
	  <td><code>FE_TONEAREST</code></td>
	  <td><code>FE_DFL_ENV</code></td>
	</tr>
	<tr>
	  <td><code>FE_INVALID</code></td>
	  <td><code>FE_ALL_EXCEPT</code></td>
	  <td><code>FE_TOWARDZERO</code></td>
	</tr>
	<tr>
	  <td>Types:</td>
	  <td><code>fenv_t</code></td>
	  <td><code>fexcept_t</code></td>
	</tr>
	<tr>
	  <td>Functions:</td>
	</tr>
	<tr>
	  <td><code>feclearexcept</code></td>
	  <td><code>fesetexceptflag</code></td>
	  <td><code>fesetround</code></td>
	  <td><code>fesetenv</code></td>
	</tr>
	<tr>
	  <td><code>fegetexceptflag</code></td>
	  <td><code>fetestexcept</code></td>
	  <td><code>fegetenv</code></td>
	  <td><code>feupdateenv</code></td>
	</tr>
	<tr>
	  <td><code>feraiseexcept</code></td>
	  <td><code>fegetround</code></td>
	  <td><code>feholdexcept</code></td>
	</tr>
      </table>
    </ins>
    <p><ins>The contents of this header
      are the same as the Standard C library header
      <code>&lt;fenv.h></code>.</ins></p>
  </blockquote>
  <h3>26.8 &emsp; C library</h3>
  <p>Change paragraph 1:</p>
  <blockquote>
    <p>The header <code>&lt;ctgmath></code>
      simply includes the headers
      <del><code>&lt;ccomplex></code></del>
      <ins><code>&lt;complex></code></ins>
      and <code>&lt;cmath></code>.</p>
  </blockquote>
  <p>Change paragraph 2:</p>
  <blockquote>
    <p>[ <em>Note:</em>
      The overloads provided in C by type-generic macros
      are already provided in
      <del><code>&lt;ccomplex></code></del>
      <ins><code>&lt;complex></code></ins>
      and <code>&lt;cmath></code>
      by &ldquo;sufficient&rdquo; additional overloads.
      &mdash;<em>end note</em> ]</p>
  </blockquote>
  <p>Change the references to the C standard for paragraph 11:</p>
  <blockquote>
    <p>See also: ISO C <del>7.5, 7.10.2, 7.10.6</del>
      <ins>7.12, 7.22.2, 7.22.6</ins>.</p>
  </blockquote>
  <h3>27.4.1 &emsp; Overview</h3>
  <p>Change paragraph 3:</p>
  <blockquote>
    <p>Mixing operations
      on corresponding wide- and narrow-character streams
      follows the same semantics as mixing such operations on FILEs,
      as specified in <del>Amendment 1 of</del>
      the ISO C standard.</p>
  </blockquote>
  <h3>27.9.2 &emsp; C library files</h3>
  <p>Change paragraph 1:</p>
  <blockquote>
    <p>Table 133 describes header <code>&lt;cstdio></code>.
      <del>[ <em>Note:</em>
	C++ does not define the function <code>gets</code>.
	&mdash;<em>end note</em> ]</del></p>
  </blockquote>
  <p>Add a new paragraph following paragraph 1:</p>
  <blockquote>
    <p><ins>The contents of this header
      are the same as the Standard C library header
      <code>&lt;stdio.h></code>.</ins></p>
  </blockquote>
  <p>Change table 133:</p>
  <blockquote>
    <pre>clearerr fopen   fsetpos putchar snprintf vscanf
fclose   fprintf ftell   puts    sprintf  vsnprintf
feof     fputc   fwrite  remove  sscanf   vsprintf
ferror   fputs   getc    rename  tmpfile  vsscanf
fflush   fread   getchar rewind  tmpnam   <ins>vfscanf</ins>
fgetc    freopen perror  scanf   ungetc
fgetpos  fscanf  printf  setbuf  vfprintf
fgets    fseek   putc    setvbuf vprintf</pre>
  </blockquote>
  <p>Change the references to the C standard for paragraph 2:</p>
  <blockquote>
    <p>See also: ISO C <del>7.9, Amendment 1 4.6.2</del>
      <ins>7.21</ins>.</p>
  </blockquote>
  <h3>D.3 &emsp; C standard library headers</h3>
  <p>Change paragraph 1:</p>
  <blockquote>
    <p>For compatibility with the C standard library
      <del>and the C Unicode TR</del>,
      the C++ standard library provides the <del>26</del>
      <ins>25</ins> C headers,
      as shown in Table 154.</p>
  </blockquote>
  <p>Change table 154:</p>
  <blockquote>
    <pre>&lt;assert.h>  &lt;inttypes.h> &lt;signal.h>   &lt;stdio.h>  &lt;wchar.h>
<del>&lt;complex.h></del> &lt;iso646.h>   &lt;stdalign.h> &lt;stdlib.h> &lt;wctype.h>
&lt;ctype.h>   &lt;limits.h>   &lt;stdarg.h>   &lt;string.h>
&lt;errno.h>   &lt;locale.h>   &lt;stdbool.h>  &lt;tgmath.h>
&lt;fenv.h>    &lt;math.h>     &lt;stddef.h>   &lt;time.h>
&lt;float.h>   &lt;setjmp.h>   &lt;stdint.h>   &lt;uchar.h></pre>
  </blockquote>
</body>
</html>
