On Thursday, 17 March 2016 at 06:55:34 UTC, Shachar Shemesh wrote:
On 16/03/16 23:50, tsbockman wrote:
On Wednesday, 16 March 2016 at 16:40:49 UTC, Shachar Shemesh wrote:
...

People who are marginally familiar with integer promotion will not be surprised to know that the program prints "256". What is surprising to
me is that this produced neither error nor warning.

The comparable program in C++, when compiled with gcc, correctly warns about signed/unsigned comparison (though, to be fair, it seems that
clang doesn't).

While this particular issue can and should be addressed in the compiler
(see my other reply), in the mean time how about trying out my
`checkedint` DUB package?

I'm afraid that paying run-time cost to verify correctness is out of the question for the type of product weka is building.

You could use the `DebugInt` wrapper. It aliases to `SafeInt` in debug and unittest mode, to find problems (many, including the specific one in this thread, are detected at compile time). Then, in release mode, it aliases to the built-in types for maximum speed.

Also, for almost all real world programs only a small percentage of the code actually affects performance much. Using `SafeInt` or `SmartInt`*everywhere* in a release build will reduce performance by about 30% - but using it *almost* everywhere, except in the program's hot spots, shouldn't measurably reduce performance at all.

Reply via email to