Boost logo

Boost :

Subject: Re: [boost] safe integer library -- the scope
From: Robert Ramey (ramey_at_[hidden])
Date: 2015-12-11 21:10:01

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:


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

Boost list run by bdawes at, gregod at, cpdaniel at, john at