C++ Unexpected Integer Promotion
问题 I was writing some code recently that was actually supposed to test other code, and I stumbled upon a surprising case of integer promotion. Here's the minimal testcase: #include <cstdint> #include <limits> int main() { std::uint8_t a, b; a = std::numeric_limits<std::uint8_t>::max(); b = a; a = a + 1; if (a != b + 1) return 1; else return 0; } Surprisingly this program returns 1. Some debugging and a hunch revealed that b + 1 in the conditional was actually returning 256, while a + 1 in