You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
f2(new int[n], m); // bad: the wrong number of elements can be passed to f()
617
+
f2(new int[n], m); // bad: a wrong number of elements can be passed to f()
616
618
}
617
619
618
620
Passing the number of elements as an argument is better (and far more common) than just passing the pointer and relying on some (unstated) convention for knowing or discovering the number of elements. However (as shown), a simple typo can introduce a serious error. The connection between the two arguments of `f2()` is conventional, rather than explicit.
@@ -1000,7 +1002,8 @@ The use of a non-local control is potentially confusing, but controls only imple
1000
1002
1001
1003
Reporting through non-local variables (e.g., `errno`) is easily ignored. For example:
1002
1004
1003
-
fprintf(connection, "logging: %d %d %d\n", x, y, s); // don't: no test of printf's return value
1005
+
// don't: no test of printf's return value
1006
+
fprintf(connection, "logging: %d %d %d\n", x, y, s);
1004
1007
1005
1008
What if the connection goes down so that no logging output is produced? See I.??.
1006
1009
@@ -1439,7 +1442,8 @@ This is a major source of errors.
1439
1442
int printf(const char* ...); // bad: return negative number if output fails
1440
1443
1441
1444
template <class F, class ...Args>
1442
-
explicit thread(F&& f, Args&&... args); // good: throw system_error if unable to start the new thread
1445
+
// good: throw system_error if unable to start the new thread
1446
+
explicit thread(F&& f, Args&&... args);
1443
1447
1444
1448
##### Note: What is an error?
1445
1449
@@ -1993,7 +1997,8 @@ Functions with complex control structures are more likely to be long and more li
1993
1997
Consider:
1994
1998
1995
1999
double simpleFunc(double val, int flag1, int flag2)
1996
-
// simpleFunc: takes a value and calculates the expected ASIC output, given the two mode flags.
2000
+
// simpleFunc: takes a value and calculates the expected ASIC output,
2001
+
// given the two mode flags.
1997
2002
{
1998
2003
1999
2004
double intermediate;
@@ -2036,12 +2041,14 @@ We can refactor:
2036
2041
}
2037
2042
2038
2043
double simpleFunc(double val, int flag1, int flag2)
2039
-
// simpleFunc: takes a value and calculates the expected ASIC output, given the two mode flags.
2044
+
// simpleFunc: takes a value and calculates the expected ASIC output,
0 commit comments