Does the C++ standard guarantee that std::uintmax_t can hold all values of std::size_t?

前端 未结 1 1953
难免孤独
难免孤独 2021-02-12 11:05

Does the C++ standard guarantee (either by explicitly stating it or implicitly by logical deduction) that std::uintmax_t can hold all values of std::size_t

1条回答
  •  爱一瞬间的悲伤
    2021-02-12 11:22

    Yes.

    size_t is defined to be an unsigned integer type large enough to contain the size of any object. uintmax_t is defined to be able to store any value of any unsigned integer type. So if size_t can store it, uintmax_t can store it.

    Definition of size_t from C++11 §18.2:

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

    Definition of uintmax_t from C99 §7.18.1.5 (it is included in C++ by normative reference):

    The following type designates an unsigned integer type capable of representing any value of any unsigned integer type:

    uintmax_t
    

    0 讨论(0)
提交回复
热议问题