And put sensible limits and checks in processing untrusted data (that is, everything that comes from the outside)
And put sensible limits and checks in processing untrusted data (that is, everything that comes from the outside)
With signed ints, you can notice that '2-3' has below 0, and act accordingly. If you do '2-3' with unsigned ints, there is not really any way of finding out something went wrong (other than looking for very large numbers).
Of course, particularly in a financal system, you should probably use an integer type which throws/aborts if an out-of-bounds error occurs.
Slightly better is 64bit signed. There can always be overflow though. The reason these values are POD's is because tickers move around at a very high speed.
For instance: http://google-styleguide.googlecode.com/svn/trunk/cppguide.x...
4e9 is invalid but in the middle of the way (more often than not) this may be interpreted as a negative number.
Hence you need to check for value 'bigger than allowed' and 'smaller than allowed'
For unsigned ints, there is a natural smallest value allowed: zero.
You're free to not follow my advice though.
And the google style guide is subtle, it's not what you're implying. You can't use 'short' for example unless explicitly.
nanex
Wrong example:
unsigned int z = x - y;
if (z > BIG_NUMBER) {
return false;
}
Good example: if (y > x) {
return false;
}
unsigned int z = x - y;Logic errors are rare but not that rare. At sea level you can expect ~1 bit flip in 4GB of memory every 24 hours. Often it's in an invalid line or gets overwritten anyway, but for applications like this where one logic error can cost you your shirt, application of hardware-level error checking (ECC, SEU detection and correction, etc).