From 330b170e77bc40def4de547a8aa0cb5f48460895 Mon Sep 17 00:00:00 2001 From: Vladislav Yaroslavlev Date: Sun, 23 Aug 2015 01:52:26 +0300 Subject: [PATCH] Update 04-Considering_Safety.md --- 04-Considering_Safety.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/04-Considering_Safety.md b/04-Considering_Safety.md index 8ca1849..fb4badd 100644 --- a/04-Considering_Safety.md +++ b/04-Considering_Safety.md @@ -94,11 +94,13 @@ Use the C++-style cast (static\_cast<>, dynamic\_cast<> ...) instead of the C-st double x = getX(); int i = (int) x; -// Good Idea +// Not a Bad Idea int i = static_cast(x); ``` Additionally the C++ cast style is more visible and has the possibility to search for. +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. + ## Additional Resources [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.