2251. C++ library should define ssize_t

Section: 21.2 [support.types] Status: NAD Submitter: Matt Austern Opened: 2013-04-19 Last modified: 2016-02-10

Priority: 3

View all other issues in [support.types].

View all issues with NAD status.

Discussion:

The C++ standard library defines size_t, a typedef for an implementation defined unsigned integer type that can represent the sizes of objects. The POSIX standard augments this with ssize_t, a typedef for a signed integer type that corresponds to size_t.

The ssize_t typedef is useful — useful enough that the C++ standard even refers to it. (In a non-normative footnote in 30.5.2 [stream.types].) 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 ssize_t to 21.2 [support.types].

[2013-09-29, Suggested wording from Jayson Oldfather]

I decided to use the phrase to describe ssize_t below because of the text describing it in the POSIX standard. In it, it describes ssize_t with the value range of [-1,{SSIZE_MAX}]. SSIZE_MAX is specified in the POSIX standard as a minimum value of _POSIX_SSIZE_MAX. This macro is referenced in the wording below.

[Lenexa 2015-05-05: NAD - no consensus for a change]

Billy : ssize_t that was promised to be signed, was based on rsize_t from safe secure C

NM : ssize_t s ptrdif_t

Z : ptrdiff_t is full range, ssize_t has only -1 as negative value

Billy : motivations for ptrdiff_T, ssize_t and rsize_T all fuzzy. - Reads rsize max -

NM : ptrdiff_T not big enough to rep difference of pointers anymore

STL : description incorporates posixisms

Billy : Don't need it

NM : rather remove it from footnote

Z : Name has precise meaning

STL : everyone understands ptrdiff_t is signed counterpart to size_t

Billy : Not in all implementations anymore

DK : footnote says something different from ...

Z/NM : off_t historically tainted

STL : we have a type trait to make signed version of size_t. we should just use that

MC : NAD; is feature request

TP : It's not cstdsef

Proposed resolution:

  1. Ammend 21.2 [support.types], Table 30 as indicated:

    Table 30 — Header <cstddef> synopsis
    Type Name(s)
    Macros: NULL offset_t
    Types: ptrdiff_t ssize_t size_t max_align_t nullptr_t

    Add the following paragraph to describe ssize_t

    -?- The type ssize_t is an implementation-defined signed integer type that shall contain the minimum range [-1, {SSIZE_MAX}] where SSIZE_MAX is specified at a minimum of _POSIX_SSIZE_MAX.

    Ammend p7 as follows:

    -7- [Note: It is recommended that implementations choose types for ptrdiff_t, ssize_t, and size_t whose integer conversion ranks …