<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 841: cstdint.syn inconsistent with C99</title>
<meta property="og:title" content="Issue 841: cstdint.syn inconsistent with C99">
<meta property="og:description" content="C++ library issue. Status: NAD Editorial">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue841.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#NAD_Editorial">NAD Editorial</a> status.</em></p>
<h3 id="841"><a href="lwg-closed.html#841">841</a>. cstdint.syn inconsistent with C99</h3>
<p><b>Section:</b> 17.4.1 <a href="https://wg21.link/cstdint.syn">[cstdint.syn]</a> <b>Status:</b> <a href="lwg-active.html#NAD_Editorial">NAD Editorial</a>
 <b>Submitter:</b> Martin Sebor <b>Opened:</b> 2008-05-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#cstdint.syn">issues</a> in [cstdint.syn].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#NAD Editorial">NAD Editorial</a> status.</p>
<p><b>Discussion:</b></p>
   <p>

In specifying the names of macros and types defined in
header <code>&lt;stdint.h&gt;</code>, C99 makes use of the
symbol <code><i>N</i></code> to accommodate unusual platforms with
word sizes that aren't powers of two. C99
permits <code><i>N</i></code> to take on any positive integer value
(including, for example, 24).

   </p>
   <p>

In  [stdint.sy] Header <code>&lt;cstdint&gt;</code>
synopsis, C++ on the other hand, fixes the value
of <code><i>N</i></code> to 8, 16, 32, and 64, and specifies only
types with these exact widths. 

   </p>
   <p>

In addition, paragraph 1 of the same section makes use of a rather
informal shorthand notation to specify sets of macros. When
interpreted strictly, the notation specifies macros such
as <code>INT_8_MIN</code> that are not intended to be specified.

   </p>
   <p>

Finally, the section is missing the usual table of symbols defined
in that header, making it inconsistent with the rest of the
specification.

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

I propose to use the same approach in the C++ spec as C99 uses, that
is, to specify the header synopsis in terms of "exposition only" types
that make use of the symbol <code><i>N</i></code> to denote one or
more of a theoretically unbounded set of widths.

   </p>
   <p>

Further, I propose to add a new table to section listing the symbols
defined in the header using a more formal notation that avoids
introducing inconsistencies.

   </p>
   <p>

To this effect, in  [stdint.sy]
Header <code>&lt;cstdint&gt;</code> synopsis, replace both the
synopsis and paragraph 1 with the following text:

   </p>
   <blockquote>
     <p>
     </p>
       <ol>
         <li>

In the names defined in the <code>&lt;cstdint&gt;</code> header, the
symbol <code><i>N</i></code> represents a positive decimal integer
with no leading zeros (e.g., 8 or 24, but not 0, 04, or 048). With the
exception of exact-width types, macros and types for values
of <code><i>N</i></code> in the set of 8, 16, 32, and 64 are
required. Exact-width types, and any macros and types for values
of <code><i>N</i></code> other than 8, 16, 32, and 64 are
optional. However, if an implementation provides integer types with
widths of 8, 16, 32, or 64 bits, the corresponding exact-width types
and macros are required.

         </li>
       </ol>
     <pre>
namespace std {

   // required types

   // Fastest minimum-width integer types
   typedef <i>signed integer type</i>   int_fast8_t;
   typedef <i>signed integer type</i>   int_fast16_t;
   typedef <i>signed integer type</i>   int_fast32_t;
   typedef <i>signed integer type</i>   int_fast64_t;

   typedef <i>unsigned integer type</i> uint_fast8_t;
   typedef <i>unsigned integer type</i> uint_fast16_t;
   typedef <i>unsigned integer type</i> uint_fast32_t;
   typedef <i>unsigned integer type</i> uint_fast64_t;

   // Minimum-width integer types
   typedef <i>signed integer type</i>   int_least8_t;
   typedef <i>signed integer type</i>   int_least16_t;
   typedef <i>signed integer type</i>   int_least32_t;
   typedef <i>signed integer type</i>   int_least64_t;

   typedef <i>unsigned integer type</i> uint_least8_t;
   typedef <i>unsigned integer type</i> uint_least16_t;
   typedef <i>unsigned integer type</i> uint_least32_t;
   typedef <i>unsigned integer type</i> uint_least64_t;

   // Greatest-width integer types
   typedef <i>signed integer type</i>   intmax_t;
   typedef <i>unsigned integer type</i> uintmax_t;

   // optionally defined types

   // Exact-width integer types
   typedef <i>signed integer type</i>   int<i>N</i>_t;
   typedef <i>unsigned integer type</i> uint<i>N</i>_t;

   // Fastest minimum-width integer types for values
   // of <i>N</i> other than 8, 16, 32, and 64
   typedef <i>signed integer type</i>   uint_fast<i>N</i>_t;
   typedef <i>unsigned integer type</i> uint_fast<i>N</i>_t;

   // Minimum-width integer types for values
   // of <i>N</i> other than 8, 16, 32, and 64
   typedef <i>signed integer type</i>   uint_least<i>N</i>_t;
   typedef <i>unsigned integer type</i> uint_least<i>N</i>_t;

   // Integer types capable of holding object pointers
   typedef <i>signed integer type</i>   intptr_t;
   typedef <i>signed integer type</i>   intptr_t;

}</pre>
   </blockquote>
   <p>

[Note to editor: Remove all of the existing paragraph 1 from  [stdint.sy].]

   </p>
   <blockquote><p>
     Table ??: Header <code>&lt;cstdint&gt;</code> synopsis
	 </p>
     <table border="1">
       <thead>
         <tr>
           <th>Type</th>
           <th colspan="3">Name(s)</th>
         </tr>
       </thead>
       <tbody>
         <tr>
           <td rowspan="11"><b>Macros:</b></td>
           <td><code>INT<i>N</i>_MIN</code></td>
           <td><code>INT<i>N</i>_MAX</code></td>
           <td><code>UINT<i>N</i>_MAX</code></td>
         </tr>
         <tr>
           <td><code>INT_FAST<i>N</i>_MIN</code></td>
           <td><code>INT_FAST<i>N</i>_MAX</code></td>
           <td><code>UINT_FAST<i>N</i>_MAX</code></td>
         </tr>
         <tr>
           <td><code>INT_LEAST<i>N</i>_MIN</code></td>
           <td><code>INT_LEAST<i>N</i>_MAX</code></td>
           <td><code>UINT_LEAST<i>N</i>_MAX</code></td>
         </tr>
         <tr>
           <td><code>INTPTR_MIN</code></td>
           <td><code>INTPTR_MAX</code></td>
           <td><code>UINTPTR_MAX</code></td>
         </tr>
         <tr>
           <td><code>INTMAX_MIN</code></td>
           <td><code>INTMAX_MAX</code></td>
           <td><code>UINTMAX_MAX</code></td>
         </tr>
         <tr>
           <td><code>PTRDIFF_MIN</code></td>
           <td><code>PTRDIFF_MAX</code></td>
           <td><code>PTRDIFF_MAX</code></td>
         </tr>
         <tr>
           <td><code>SIG_ATOMIC_MIN</code></td>
           <td><code>SIG_ATOMIC_MAX</code></td>
           <td><code>SIZE_MAX</code></td>
         </tr>
         <tr>
           <td><code>WCHAR_MIN</code></td>
           <td><code>WCHAR_MAX</code></td>
         <td></td>
         </tr>
         <tr>
           <td><code>WINT_MIN</code></td>
           <td><code>WINT_MAX</code></td>
           <td></td>
         </tr>
         <tr>
           <td><code>INT<i>N</i>_C()</code></td>
           <td><code>UINT<i>N</i>_C()</code></td>
           <td></td>
         </tr>
         <tr>
           <td><code>INTMAX_C()</code></td>
           <td><code>UINTMAX_C()</code></td>
           <td></td>
         </tr>
         <tr>
           <td rowspan="5"><b>Types:</b></td>
           <td><code>int<i>N</i>_t</code></td>
           <td><code>uint<i>N</i>_t</code></td>
           <td></td>
         </tr>
         <tr>
           <td><code>int_fast<i>N</i>_t</code></td>
           <td><code>uint_fast<i>N</i>_t</code></td>
           <td></td>
         </tr>
         <tr>
           <td><code>int_least<i>N</i>_t</code></td>
           <td><code>uint_least<i>N</i>_t</code></td>
           <td></td>
         </tr>
         <tr>
           <td><code>intptr_t</code></td>
           <td><code>uintptr_t</code></td>
           <td></td>
         </tr>
         <tr>
           <td><code>intmax_t</code></td>
           <td><code>uintmax_t</code></td>
           <td></td>
         </tr>
       </tbody>
     </table>
   </blockquote>
 




</body>
</html>
