Question: Let's say I have to accept a size as an argument to an interface which deals with arrays. For e.x.

```
void doSomethingRelatedToArrays(const size_t length)

```

Here, I used `size_t` with the following in mind:

* length must always be positive
* `size_t` is always typedef-ed to the largest unsigned integer type in the system. `std::size_t` can store the maximum size of a theoretically possible object of any type.

However, I should not use unsigned types in my interfaces because the client can pass in a negative number, which is implicitly converted to an unsigned number and I do not have any way of validating it in my method. Refer to Scott Meyer's article on this subject [here](http://www.aristeia.com/Papers/C++ReportColumns/sep95.pdf).

So, I should pass in signed integer type to the API. But how can I get the largest signed integer type in the system? Is there any typedef similar to `size_t` which is signed? Or should I just use `size_t` instead?

Answer: 
The signed equivalent of `size_t` is simply `ssize_t` but this type is not defined in C99 standard even if it is known to many compilers.

For the C99 standard the largest signed integer type is defined as `intmax_t`.

Reference : 7. Library / 7.18 Integer types / 7.18.1.5 Greatest-width integer types
The largest signed integer type in recent C and C++ standards is `long long`. Until there is a type wider than `long long` you can always use it. If you want to be more future proof, use `intmax_t`.

---

> 
> `size_t` is always typedef-ed to the largest unsigned integer type in the system
> 
> 
> 

That's completely incorrect!!! ❌
================================

`size_t` in 32-bit systems is typically also a 32-bit type, which obviously **not** the widest type possible. It's only guaranteed to be *big enough to represent the size of the biggest object* on the system. `long long` is obviously much wider in that cases. In many 16-bit systems it has only 16 bits, not even the same range as `long`.

---

In case `size_t` is needed, `ptrdiff_t` can be used as a signed counterpart. But it's not the biggest type either.

> 
> For `char` arrays shorter than `PTRDIFF_MAX`, `std::ptrdiff_t` acts as the signed counterpart of `std::size_t`: it can store the size of the array of any type and is, on most platforms, synonymous with `std::intptr_t`
> 
> 
> <http://en.cppreference.com/w/cpp/types/ptrdiff_t>
> 
> 
> 

In C++20 [`std::ssize`](https://en.cppreference.com/w/cpp/iterator/size) was introduced and guess what, **it also uses `ptrdiff_t` as the signed counterpart of `size_t`**