<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2251: C++ library should define ssize_t</title>
<meta property="og:title" content="Issue 2251: C++ library should define ssize_t">
<meta property="og:description" content="C++ library issue. Status: NAD">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2251.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">NAD</a> status.</em></p>
<h3 id="2251"><a href="lwg-closed.html#2251">2251</a>. C++ library should define <code>ssize_t</code></h3>
<p><b>Section:</b> 17.2 <a href="https://wg21.link/support.types">[support.types]</a> <b>Status:</b> <a href="lwg-active.html#NAD">NAD</a>
 <b>Submitter:</b> Matt Austern <b>Opened:</b> 2013-04-19 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>3
</p>
<p><b>View all other</b> <a href="lwg-index.html#support.types">issues</a> in [support.types].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#NAD">NAD</a> status.</p>
<p><b>Discussion:</b></p>

<p>
The C++ standard library defines <code>size_t</code>, a typedef for an implementation defined unsigned integer type 
that can represent the sizes of objects. The POSIX standard augments this with <code>ssize_t</code>, a typedef for a 
signed integer type that corresponds to <code>size_t</code>.
<p/>
The <code>ssize_t</code> typedef is useful &mdash; useful enough that the C++ standard even refers to it. (In a 
non-normative footnote in 31.2.2 <a href="https://wg21.link/stream.types">[stream.types]</a>.)  Also, lots of OS vendors add it to their headers anyway, 
even though it isn't part of the C or C++ standards, because those vendors are trying to define headers that 
conform to multiple standards at once. We should make users' and implementers' lives easier by adding 
<code>ssize_t</code> to 17.2 <a href="https://wg21.link/support.types">[support.types]</a>.
</p>

<p><i>[2013-09-29, Suggested wording from Jayson Oldfather]</i></p>

<p> 
I decided to use the phrase to describe <code>ssize_t</code> below because of the text describing it in the 
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_types.h.html#tag_13_67">POSIX</a> standard. 
In it, it describes <code>ssize_t</code> with the value range of <code>[-1,{SSIZE_MAX}]</code>.
<code>SSIZE_MAX</code> is specified in the <a href="http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html#tag_13_24">POSIX</a> 
standard as a minimum value of <code>_POSIX_SSIZE_MAX</code>. This macro is referenced in the wording below.
</p>

<p><i>[Lenexa 2015-05-05: NAD - no consensus for a change]</i></p>

<p>Billy : ssize_t that was promised to be signed, was based on rsize_t from safe secure C</p>
<p>NM : ssize_t s ptrdif_t</p>
<p>Z : ptrdiff_t is full range, ssize_t has only -1 as negative value</p>
<p>Billy : motivations for ptrdiff_T, ssize_t and rsize_T all fuzzy. - Reads rsize max -</p>
<p>NM : ptrdiff_T not big enough to rep difference of pointers anymore</p>
<p>STL : description incorporates posixisms</p>
<p>Billy : Don't need it</p>
<p>NM : rather remove it from footnote</p>
<p>Z : Name has precise meaning</p>
<p>STL : everyone understands ptrdiff_t is signed counterpart to size_t</p>
<p>Billy : Not in all implementations anymore</p>
<p>DK : footnote says something different from ...</p>
<p>Z/NM : off_t historically tainted</p>
<p>STL : we have a type trait to make signed version of size_t. we should just use that</p>
<p>MC : NAD; is feature request</p>
<p>TP : It's not cstdsef</p>



<p id="res-2251"><b>Proposed resolution:</b></p>
<ol>
<li>
<p>
Ammend 17.2 <a href="https://wg21.link/support.types">[support.types]</a>, Table 30 as indicated:
</p>

<blockquote>
<table border="1">
<caption>Table 30 &mdash; Header <code>&lt;cstddef&gt;</code> synopsis</caption>
<tr>
<th>Type</th>
<th>Name(s)</th>
</tr>

<tr>
<td>
<b>Macros:</b>
</td>
<td>
<code>NULL offset_t</code>
</td>
</tr>

<tr>
<td>
<b>Types:</b>
</td>
<td>
<code>ptrdiff_t <ins>ssize_t</ins> size_t max_align_t nullptr_t</code>
</td>
</tr>
</table>
</blockquote>

<p>Add the following paragraph to describe <code>ssize_t</code></p>
<blockquote><p><ins>
-?- The type <code>ssize_t</code> is an implementation-defined signed integer type that shall contain the minimum range 
<code>[-1, {SSIZE_MAX}]</code> where <code>SSIZE_MAX</code> is specified at a minimum of <code>_POSIX_SSIZE_MAX</code>.</ins>
</p></blockquote>
<p>Ammend p7 as follows:</p>
<blockquote><p>
-7- [<i>Note:</i> It is recommended that implementations choose types for <code>ptrdiff_t<ins>, ssize_t,</ins></code> and <code>size_t</code> whose integer conversion ranks &hellip;</p></blockquote>
</li>
</ol>





</body>
</html>
