is size_t always unsigned?

后端 未结 6 1857
陌清茗
陌清茗 2020-12-01 07:07

As title: is size_t always unsigned, i.e. for size_t x, is x always >= 0 ?

6条回答
  •  情话喂你
    2020-12-01 07:44

    The size_t should follow the same definition as the C standard, and in several places in the C++ standard it implies it's unsigned natura (particularly in the allocator template argument definitions).

    On the C++ Standard, section 18.1 (ISO/IEC 14882 - First edition 1998-01-01):

    Table 15 lists as defined types: ptrdiff_t and size_t

    3 The contents are the same as the Standard C library header , with the following changes: 4 The macro NULL is an implementation-defined C++ null pointer constant in this International Standard (4.10).

    The macro offsetof accepts a restricted set of type arguments in this International Standard. type shall be a POD structure or a POD union (clause 9). The result of applying the offsetof macro to a field that is a static data member or a function member is undefined. SEE ALSO: subclause 5.3.3, Sizeof, subclause 5.7, Additive operators, subclause 12.5, Free store, and ISO C subclause 7.1.6.

提交回复
热议问题