SafeInt 3 on CodePlex!

I have finally found a stable place to keep SafeInt. It can now be found at In terms of the code, this is exactly the same stuff as we're using internally. This version is documented a little better than the master copy that's checked into the Office development depot, but other than that, should be the same.

Some notable changes from 2.0 –

  • Replaceable exceptions – the exception handler class is now a template argument, so if your project has well developed exception classes, this makes it easier.
  • Solved the short-circuiting problem – I previously had overloads for the || and && operators, which seemed to be the lesser of several evils. As it turns out, adding a cast to bool and removing the overloads causes things to short-circuit properly.
  • Added limited floating point support – you can now initialize a SafeInt with a floating point number, as well as assign to a float.
  • Several non-throwing functions have been added to check operations when you'd prefer not to throw on failure. All of the internal code for all of the operators is available in both throwing and non-throwing forms in the header.

If you're currently using SafeInt 2.0, this should just drop in without causing much work. There have also been a small number of bug fixes, which will not be ported back to 2.0. This is the only supported version. To make "support" clear, this is released under the Microsoft Public License (Ms-PL). I believe that it works well, it passes our internal test rig, and we're using it in several thousand places in Office, Windows, and other projects. However, it is still up to you to test it. If you think you've found a problem, please let me know. Likewise, if you have a suggestion, also let me know. This should be very stable at this point.

Speaking of suggestions, I had to talk to a number of people about the issues with actually publishing code that we're really using, as opposed to sample code. If you have suggestions, write them out. Sample code illustrating a bug is OK. Please do not send me a diff – I can't take it. If you want to make major changes, feel free to fork it and maintain your version somewhere else, though you need to heed the license.

If you happen to be curious about why this is 3.0.11p, that's major version 3, minor version 0, 11th check-in internally, and 'p' is for public.

Skip to main content