Pattern: Misused integer type
Issue: -
Of the built-in C++ integer types, the only one used is int
. If a program needs a variable of a different size, use a precise-width integer type from <stdint.h>
, such as int16_t
. If your variable represents a value that could ever be greater than or equal to 2^31 (2GiB), use a 64-bit type such as int64_t
. Keep in mind that even if your value won't ever be too large for an int
, it may be used in intermediate calculations which may require a larger type. When in doubt, choose a larger type.