Skip to content

Commit 330b170

Browse files
author
Vladislav Yaroslavlev
committed
Update 04-Considering_Safety.md
1 parent d1064a6 commit 330b170

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
@@ -94,11 +94,13 @@ Use the C++-style cast (static\_cast<>, dynamic\_cast<> ...) instead of the C-st
9494
double x = getX();
9595
int i = (int) x;
9696

97-
// Good Idea
97+
// Not a Bad Idea
9898
int i = static_cast<int>(x);
9999
```
100100
Additionally the C++ cast style is more visible and has the possibility to search for.
101101

102+
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.
103+
102104
## Additional Resources
103105

104106
[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)