Difference between size_t and std::size_t

C’s size_t and C++’s std::size_t are both same. In C, it’s defined in <stddef.h> and in C++, its defined in <cstddef> whose contents are the same as C header (see the quotation below). Its defined as unsigned integer type of the result of the sizeof operator. C Standard says in ยง17.7/2, size_t which is the … Read more

Does “std::size_t” make sense in C++?

There seems to be confusion among the stackoverflow crowd concerning this ::size_t is defined in the backward compatibility header stddef.h . It’s been part of ANSI/ISO C and ISO C++ since their very beginning. Every C++ implementation has to ship with stddef.h (compatibility) and cstddef where only the latter defines std::size_t and not necessarily ::size_t. … Read more

Why is size_t unsigned?

size_t is unsigned for historical reasons. On an architecture with 16 bit pointers, such as the “small” model DOS programming, it would be impractical to limit strings to 32 KB. For this reason, the C standard requires (via required ranges) ptrdiff_t, the signed counterpart to size_t and the result type of pointer difference, to be … Read more