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?
There is never a reason to use
shortin a C99 environment that has 16-bit integers; you can useint16_t,int_fast16_torint_least16_tinstead.The main reasons for using
shortis backward compatibility with C89 or older environments, which do not offer these types, or with libraries usingshortas 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 provideint16_t.