This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 117a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2025-04-13


1122. Circular definition of std::size_t

Section: 7.6.2.5  [expr.sizeof]     Status: C++11     Submitter: GB     Date: 2010-08-02

[Voted into the WP at the November, 2010 meeting.]

N3092 comment GB 24

The return type of the sizeof operator is defined as being of type std::size_t, defined in library 17.2 [support.types]. This, in turn, says that size_t is defined in the C standard, which in turn says that size_t is defined as the type of the result of the sizeof operator!

The C definition of sizeof returns an implementation-defined unsigned integer type, recommended not to have β€œan integer conversion rank greater than signed long int, unless the implementation supports objects large enough to make this necessary.”

Proposed resolution (September, 2010):

Add the following three paragraphs after 17.2 [support.types] paragraph 4:

The type ptrdiff_t is an implementation-defined signed integer type that can hold the difference of two subscripts in an array object, as described in 7.6.6 [expr.add].

The type size_t is an implementation-defined unsigned integer type that is large enough to contain the size in bytes of any object.

[Note: It is recommended that implementations choose types for ptrdiff_t and size_t whose integer conversion ranks (7.3.15 [conv.bool]) are no greater than that of signed long int unless a larger size is necessary to contain all the possible values. β€”end note]