When to use short instead of int?
c
Solution
There is never a reason to use `short` in a C99 environment that has 16-bit integers; you can use `int16_t`, `int_fast16_t` or `int_least16_t` instead.
The main reasons for using `short` is backward compatibility with C89 or older environments, which do not offer these types, or with libraries using `short` as part of their public API, for implementing `<stdint.h>` itself, or for compatibility with platforms that do not have 16-bit integers so their C compilers do not provide `int16_t`.
Problem
Two use cases for which I would consider `short` come to mind: - I want an integer type that's at least 16 bits in size - I want an integer type that's exactly 16 bits in size In the first case, since `int` is guaranteed to be at least 16 bits and is the most efficient integral data type, I would use `int`. In the second case, since the standard doesn't guarantee that `short`'s size is exactly 16 bit, I would use `int16_t` instead. So what use is short?