标签云

微信群

扫码加入我们

WeChat QR Code


I found this helpful: codemines.blogspot.ca/2007/10/…

2018年10月22日08分54秒

I think this question is quite opinion based. The presented code will run in both cases just fine, so you can use both. Except for performance reasons (no answer actually deals with performance so far) it's just personal taste.

2018年10月21日08分54秒

Later in that thread, it's shown that unsigned is vastly superior for detecting overflow in untrusted inputs. Unfortunately, the proposed "answers" to the puzzle aren't all that great. Mine is template<size_t limit> bool range_check_sum( unsigned a, unsigned b ) { return (a < limit) && (b < limit - a); } If anyone has a similarly simple and straightforward answer using signed types, I'd love to see it.

2018年10月21日08分54秒

Only when you're dealing with the size of something in bytes.

2018年10月22日08分54秒