In C++11 we are provided with fixed-width integer types, such as std::int32_t
and std::int64_t
, which are optional and therefore not optimal for writing cross-platform code. However, we also got non-optional variants for the types: e.g. the "fast" variants, e.g. std::int_fast32_t
and std::int_fast64_t
, as well as the "smallest-size" variants, e.g. std::int_least32_t
, which both are at least the specified number of bits in size.
The code I am working on is part of a C++11-based cross-platform library, which supports compilation on the most popular Unix/Windows/Mac compilers. A question that now came up is if there is an advantage in replacing the existing integer types in the code by the C++11 fixed-width integer types.
A disadvantage of using variables like std::int16_t
and std::int32_t
is the lack of a guarantee that they are available, since they are only provided if the implementation directly supports the type (according to http://en.cppreference.com/w/cpp/types/integer).
However, since int
is at least 16 bits and 16-bit are large enough for the integers used in the code, what about the usage of std::int_fast16_t
over int? Does it provide a benefit to replace all int
types by std::int_fast16_t
and all unsigned int
's by std::uint_fast16_t
in that way or is this unnecessary?
Anologously, if knowing that all supported platforms and compilers feature an int
of at least 32 bits size, does it make sense to replace them by std::int_fast32_t
and std::uint_fast32_t
respectively?