CKTIS / C++
std::int8_t — an exactly 8-bit signed integer
std::int8_t from <cstdint> is an optional alias for a signed integer type with exactly 8 bits and no padding bits. It stores values from -128 to 127. Calculations follow integral promotion rules, and explicitly converting to int is useful when printing its numeric value.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
#include <cstdint>
std::int8_t value{42};std::int8_t, provided by <cstdint>, aliases an existing type rather than introducing a distinct new type. It has exactly 8 bits, no padding bits, and a range from -128 to 127. It is optional: an implementation must provide it if it has a suitable integer type. After including the header, the INT8_MAX macro lets you check availability.
Use it when an exact width is required. If at least 8 bits is sufficient, choose std::int_least8_t; std::uint8_t, by contrast, is an optional unsigned type ranging from 0 to 255. std::int8_t can alias signed char. In C++23 code, directly inserting it into std::cout can therefore treat the value as a character; static_cast<int>(value) unambiguously requests numeric output.
In value + 7, the std::int8_t value is promoted to int, so the result also has type int. Check the range before storing the result back: an explicit conversion does not report an out-of-range error. In C++23, converting an integer to this type produces the congruent value modulo 256, rather than clamping to the nearest range boundary.
The example stores 120, calculates 127 in int, and stores the representable result back. Its expected output is 120 127 127 followed by a newline. This material targets C++23; the supplied working draft evolves and is not a frozen C++23 edition. The repository's compilation mode does not attest production-runtime behavior.
Examples
#include <cstdint>
#include <iostream>
#ifndef INT8_MAX
#error "This example requires std::int8_t"
#else
int main() {
std::int8_t value{120};
int sum = value + 7;
std::int8_t result{static_cast<std::int8_t>(sum)};
std::cout << static_cast<int>(value) << ' '
<< sum << ' ' << static_cast<int>(result) << '\n';
}
#endif
Result
120 127 127
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.