
12 Dec
2015
12 Dec
'15
2:10 a.m.
On 12/11/15 5:50 PM, Robert Ramey wrote: To belabor the point, consider this little program: #include <iostream> #include <cstdint> using namespace std; int main(){ int8_t x = 100; int y = x * x; cout << y << endl; uint32_t z1 = 100; int8_t z2 = -100; auto y2 = z1 * z2; cout << y2 << endl; return 0; } which prints out: 10000 4294957296 This is due to the application of the C++ type promotion rules. Is it any reason that C++ drives people crazy? One looks at the program and sees arithmetic. One executes the program an gets ... well I don't know what you're getting. Robert Ramey