c++ - Is it guaranteed that size_t, vector::size_type, etc typedefs won't bind to a char type? -
it possible cstdint
typedefs bind char variables. example, uint_least8_t
binds unsigned char
, , int_least8_t
binds signed char
.
does standard guarantee similar thing won't happen size_t
or similar types? or there @ least purely theoretical chance such types bind char types, unsigned char
or maybe wchar_t
?
all know std::size_t
is:
the type size_t implementation-defined unsigned integer type large enough contain size in bytes of object.
if unsigned char
fulfills condition, may used std::size_t
.
however, concern purely theoretical there not single real platform (that know of) (alright, wrong) char type used unsigned char
wide enoughstd::size_t
or like.
if super paranoid, can promote value @ least int
unary +
:
std::cout << +vector.size();
this print number if size type character type.
for reading can use variables of type std::common_type<unsigned int, std::size_t>::type
(probably through typedef
) , bounds check in case sizeof(int) > sizeof(std::size_t)
.
Comments
Post a Comment