Skip to content

Commit

Permalink
Add note about underflow
Browse files Browse the repository at this point in the history
Closes #47
  • Loading branch information
lefticus committed May 25, 2016
1 parent 75e12df commit 3bc2c04
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions 03-Style.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,16 @@ In general, using `auto` will avoid most of these issues, but not all.
Make sure you stick with the correct integer types and remain consistent with the C++ standard library. It might not warn on the platform you are currently using, but it probably will when you change platforms.
*Note that you can cause integer underflow when peforming some operations on unsigned values. For example:*
```cpp
std::vector<int> v1{2,3,4,5,6,7,8,9};
std::vector<int> v2{9,8,7,6,5,4,3,2,1};
const auto s1 = v1.size();
const auto s2 = v2.size();
const auto diff = s1 - s2; // diff underflows to a very large number
```

## Use .hpp and .cpp for Your File Extensions

Ultimately this is a matter of preference, but .hpp and .cpp are widely recognized by various editors and tools. So the choice is pragmatic. Specifically, Visual Studio only automatically recognizes .cpp and .cxx for C++ files, and Vim doesn't necessarily recognize .cc as a C++ file.
Expand Down

0 comments on commit 3bc2c04

Please sign in to comment.