From d7725aa37c850e658500e456064ebf3b8b6b9b66 Mon Sep 17 00:00:00 2001 From: Bjarne Stroustrup Date: Sat, 27 Aug 2016 21:14:16 -0400 Subject: [PATCH] ES.100 new example --- CppCoreGuidelines.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 29d5939..98ec6a3 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -10779,9 +10779,14 @@ Avoid wrong results. ##### Example - unsigned x = 100; - unsigned y = 102; - cout << abs(x-y) << '\n'; // wrong result + int x = -3; + unsigned int y = 7; + + cout << x-y << '\n'; // unsigned result, possibly 4294967286 + cout << x+y << '\n'; // unsiged result: 4 + cout << x*y << '\n'; // unsigned result, possibly 4294967275 + +It is harder to spot the problem in more realistic examples. ##### Note