-
-
Notifications
You must be signed in to change notification settings - Fork 911
Closed
Description
good rules to follow, but you might like to add a remark about computing the difference between two sizes, because even when using auto you might get unexpected behaviour, ie. value underrun:
std::size_t a=3, b = 5;
auto c = a-b;c is now some huge number, because c is still unsigned, and you don't get a warning. Also worth noting is that because std::size_t is generally defined as the largest unsigned integer type on a system, generally there is no signed type that will hold all values of a std::size_t. Thus the only safe way of computing the difference requires that you compare b<=a before you compute the difference and take appropriate action if b>a.
Metadata
Metadata
Assignees
Labels
No labels