Skip to content

Commit bf0a81c

Browse files
committed
Merge pull request #38 from vladon/patch-1
Update 04-Considering_Safety.md
2 parents ad3611d + 330b170 commit bf0a81c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

04-Considering_Safety.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,13 @@ Use the C++-style cast (static\_cast<>, dynamic\_cast<> ...) instead of the C-st
140140
double x = getX();
141141
int i = (int) x;
142142

143-
// Good Idea
143+
// Not a Bad Idea
144144
int i = static_cast<int>(x);
145145
```
146146
Additionally the C++ cast style is more visible and has the possibility to search for.
147147

148+
But consider refactoring of program logic (for example, additional checking on overflow and underflow) if you need to cast `double` to `int`. Measure three times and cut 0.9999999999981 times.
149+
148150
## Additional Resources
149151

150152
[How to Prevent The Next Heartbleed](http://www.dwheeler.com/essays/heartbleed.html) by David Wheeler is a good analysis of the current state of code safety and how to ensure safe code.

0 commit comments

Comments
 (0)