CKTIS / C++
short — signed integer type
short is a standard signed integer type equivalent to short int. Its width is at least 16 bits, but it need not occupy two bytes. In arithmetic, its values undergo integral promotion to int.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
short name{value};
short int name{value};
signed short name{value};
unsigned short name{value};short, short int, signed short, and signed short int name the same signed integer type. unsigned short and unsigned short int name its corresponding, distinct unsigned type.
short has a width of at least 16 bits and covers at least -32768 through 32767. Do not assume that sizeof(short) == 2 or that short occupies less storage than int. Check the exact range using std::numeric_limits<short>::min() and std::numeric_limits<short>::max() from <limits>.
In an expression such as temperature + increase, both short operands are promoted to int; the result has type int, not short. This promotion does not change the variables' types. Consequently, do not treat short as a way to force 16-bit arithmetic.
The example stores small temperatures in short and the addition result in int. Its assertions check the minimum guaranteed range without making the expected output implementation-dependent. This entry targets C++23; the referenced website hosts an evolving working draft rather than a frozen C++23 edition.
Examples
#include <iostream>
#include <limits>
int main() {
short temperature{-12};
short increase{5};
int result = temperature + increase;
static_assert(std::numeric_limits<short>::min() <= -32768);
static_assert(std::numeric_limits<short>::max() >= 32767);
std::cout << temperature << '\n' << result << '\n';
}
Result
-12 -7
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.